- Mastering Immutable.js
- Adam Boduch
- 111字
- 2021-07-08 10:30:11
Setting list values
When you set list values using the set() method, you're changing an existing value. More specifically, you're overwriting the current value at a given index with a new value:
const myList = List.of(1);
const myChangedList = myList.set(0, 2);
console.log('myList', myList.toJS());
// -> myList [ 1 ]
console.log('myChangedList', myChangedList.toJS());
// -> myChangedList [ 2 ]
You're updating the first list value—because the index you're passing to set() is 0—with a value of 2. Using set() like this is a good choice when you know ahead of time what the new value should be. But what about when the new value depends on the current value?
推薦閱讀
- Learning Single:page Web Application Development
- R語言數據分析從入門到精通
- OpenCV 3和Qt5計算機視覺應用開發
- Python王者歸來
- Java:Data Science Made Easy
- Easy Web Development with WaveMaker
- Scala編程實戰(原書第2版)
- Working with Odoo
- Angular開發入門與實戰
- Vue.js應用測試
- 動手打造深度學習框架
- App Inventor少兒趣味編程動手做
- Machine Learning for OpenCV
- Python全棧開發:基礎入門
- Google Maps JavaScript API Cookbook