Underscore.JS - toArray 方法



語法

_.toArray(list)

toArray 方法根據提供列表的項準備了一個數組。

示例

var _ = require('underscore');

//Example: get a array of 4 elements
result = _.toArray("abcd").slice(0,4)
console.log(result)

將上述程式儲存在 tester.js 中。執行以下命令執行此程式。

命令

\>node tester.js

輸出

[ 'a', 'b', 'c', 'd' ]
underscorejs_processing_collection.htm
廣告
© . All rights reserved.