- 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!
推薦閱讀
- OpenStack Cloud Computing Cookbook(Third Edition)
- C++面向對象程序設計(第三版)
- VMware View Security Essentials
- Python自動化運維快速入門(第2版)
- Visual C++實例精通
- RISC-V體系結構編程與實踐(第2版)
- Learning R for Geospatial Analysis
- 快速入門與進階:Creo 4·0全實例精講
- Java Web從入門到精通(第3版)
- Java Web從入門到精通(第2版)
- 貫通Tomcat開發
- SSH框架企業級應用實戰
- Microsoft Dynamics GP 2013 Cookbook
- 一步一步學Spring Boot:微服務項目實戰(第2版)
- 像程序員一樣使用MySQL