- Mastering Immutable.js
- Adam Boduch
- 147字
- 2021-07-08 10:30:10
Pushing multiple list values
Now let's try pushing multiple values to a list:
const myList = List.of(1, 2, 3);
const myChangedList = myList
.push(4)
.push(5, 6)
.push(7, 8)
.push(9);
console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]
console.log('myChangedList', myChangedList);
// -> myChangedList List [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
Here, the first three calls to push() create intermediary lists—you don't actually use them for anything other than as steps for building a new list. The final call to push() produces the value that ends up in myChangedList. You can see that push() accepts multiple values to add to the list. Of course, it would be better to make one call instead of four where possible. However, this isn't always possible depending on how your code is organized. I'm also using this as an opportunity to illustrate a concept.
推薦閱讀
- UML和模式應用(原書第3版)
- PostgreSQL for Data Architects
- 三維圖形化C++趣味編程
- SAP BusinessObjects Dashboards 4.1 Cookbook
- 網站構建技術
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- Learning ArcGIS for Desktop
- 數據結構習題解析與實驗指導
- HTML5 APP開發從入門到精通(微課精編版)
- 詳解MATLAB圖形繪制技術
- Node.js 12實戰
- 從零開始學Android開發
- Android移動應用項目化教程
- Clojure編程樂趣
- Boost.Asio C++ Network Programming Cookbook