[JS] Array.from ( )
5381 ワード
Array.from ( )
きほんけいじょう
Array.from(arrayLike[, mapFn[, thisArg]])
アレイに変換する類似アレイオブジェクトまたは重複可能オブジェクト
配列内のすべての要素を呼び出すマッピング関数
mapfnの実行時に使用する値
戻り値
例
Array.from('foo');
// ["f", "o", "o"]
const s = new Set(['foo', window]);
Array.from(s);
// ["foo", window]
function f() {
return Array.from(arguments);
}
f(1, 2, 3);
// [1, 2, 3]
let name = 'foo'
const num_array = Array.from(name, (item, index) => {return index});
console.log(name_array);
// [1, 2, 3]
アレイなしlet new_array = Array.from({length:4}, (item, idx) => { return index; });
console.log(new_array)
// [0, 1, 2, 3]
Reference
この問題について([JS] Array.from ( )), 我々は、より多くの情報をここで見つけました https://velog.io/@nulee1000/JS-Array.fromテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol