- Mastering Immutable.js
- Adam Boduch
- 116字
- 2021-07-08 10:30:10
Pushing values to lists
You can push a new value onto a list using the push() method, as follows:
const myList = List.of(1, 2, 3);
const myChangedList = myList.push(4);
console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]
console.log('myChangedList', myChangedList.toJS());
// -> myChangedList [ 1, 2, 3, 4 ]
The end result of calling push(4) is a new list. If you want to make use of this list, you have to store it somewhere. In this example, we just want to print the JSON representation of the list, and as you can see, 4 is added to myChangedList. You can also see that the contents of myList haven't changed. Of course not—it's immutable!
推薦閱讀
- 黑客攻防從入門到精通(實戰秘笈版)
- TypeScript入門與實戰
- 數據結構和算法基礎(Java語言實現)
- PyTorch Artificial Intelligence Fundamentals
- Learning SQLite for iOS
- Essential Angular
- Python機器學習編程與實戰
- Python數據結構與算法(視頻教學版)
- Machine Learning for Developers
- Mastering Drupal 8
- Android應用開發攻略
- Hands-On ROS for Robotics Programming
- Unity3D高級編程:主程手記
- JavaScript高級程序設計(第3版)
- Java程序設計項目教程(第二版)