- 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?
推薦閱讀
- Java語言程序設計
- Intel Galileo Essentials
- Hands-On Image Processing with Python
- SQL語言從入門到精通
- 精通Python自然語言處理
- C#應用程序設計教程
- 圖數據庫實戰
- 汽車人機交互界面整合設計
- Visual FoxPro 6.0程序設計
- Bootstrap for Rails
- 并行編程方法與優化實踐
- Moodle 3 Administration(Third Edition)
- 分布式架構原理與實踐
- Drupal 8 Development:Beginner's Guide(Second Edition)
- Java 7 Concurrency Cookbook