如何从 immutable.js 创建的列表中获取所有值?

How to get all values from list created by immutable.js?

我通过 Immutable.js

创建了数组
var list = Immutable.List([ 1, 2, 3 ]);

list.push('333');

// this does not show list
console.log(list);

如何获取所有值?

因为console.log(列表);不起作用。

使用推送创建新列表。然后它的最后一个元素是'333'

Console.log(list) 将打印非常冗长的列表的内部表示。使用 last 或 map。

var list = Immutable.List([ 1, 2, 3 ]);
let newList = list.push('333');

// print last element
console.log(newList.last())

// print all elements
newList.map((e)=> console.log(e))

或者你可以使用 toJS() 从不可变数组创建普通的 javascript 数组。然后打印出来。