[Javascript] Immutable opreators
JavaScript Immutable
2023-09-14 08:59:19 时间
- slice
- filter
- map
- ...spread
- concat
- Object.assign
let items = [1,2,3]; //add let newItems = [...items, 30]; //remove var filtered = newItems.filter( item => item !== 2); //update let things = [1,2,3,4,5].map(num => ({id: num})); var i = things.findIndex(item => item.id === 3); var updated = [ ...things.slice(0, i), {id: 33}, ...things.slice(i+1) ]; var state = {app: {}, items: [1]}; //add var newState = Object.assign({}, state, {app: 2, newThings: 2}); // update var newState = Object.assign({}, state, {app: 2}); var newState = { ...state, app: 2 };
相关文章
- JavaScript日期集合(今日,昨日,本周一,周末 ,月初,月末)
- JavaScript经典代码【二】【javascript判断用户点了鼠标左键还是右键】
- JavaScript经典代码【一】【javascript HTML控件获取值】
- [Javascript] Singleton Pattern
- [Javascript] Wait for Multiple JavaScript Promises to Settle with Promise.allSettled()
- [Algorithms] Solve Complex Problems in JavaScript with Dynamic Programming
- [RxJSv& Javascript] forkJoin (reactive Promise.all) & Map
- [Javascript] Redirect the browser using JavaScript
- [Javascript] How to use JavaScript's String.replace
- [Javascript] What is JavaScript Function Currying?
- [Javascript] Manage Application State with Immutable.js
- 理解javascript作用域和作用域链
- Javascript中闭包的作用域链
- [Javascript] Understanding the difference between .prototype and .__proto__ in JavaScript
- [Javascript] Convert a Callback-Based JavaScript Function to a Promise-Based One
- [Javascript] Identify and Deal with NaN in JavaScript
- [Javascript] Modifying an Immutable.js Map()
- SAP Cloud SDK for JavaScript 的搭建和使用方法介绍
- 你真的会用ABAP, Java和JavaScript里的constructor么?
- atitit.javascript调用java in swt attilax 总结
- 【华为OD机试 2023】完美走位(C++ Java JavaScript Python)
- javaScript实现归并排序
- 理解和使用 JavaScript 中的回调函数