- 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!
推薦閱讀
- 從零開始構建企業級RAG系統
- PHP+MySQL網站開發技術項目式教程(第2版)
- OpenNI Cookbook
- 數據結構習題解析與實驗指導
- C#應用程序設計教程
- SQL Server數據庫管理與開發兵書
- Visual Foxpro 9.0數據庫程序設計教程
- Node Cookbook(Second Edition)
- Learning YARN
- 新印象:解構UI界面設計
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- Responsive Web Design with jQuery
- Python Penetration Testing Essentials
- 精通Oracle 12c 數據庫管理
- C++ Primer(中文版)(第5版)