ray88’s diary

お仕事で困ったとき用の自分用の覚書

JavaScript Arrayオブジェクトの変更メソッド

JavaScript 目次 - ray88’s diary
JavaScript Arrayオブジェクト・配列を取り扱う - ray88’s diary
JavaScript Arrayオブジェクトの主なメンバー - ray88’s diary
JavaScript Arrayオブジェクトのアクセサメソッド・プロパティ - ray88’s diary

function myFunction(){
  const array = ['Bob','Tom','Jay','Tom'];
  
  array.push('Dan');
  console.log(array);//['Bob','Tom','Jay','Dan','Tom','Dan']

  array.unshift('Ivy');
  console.log(array);//['Ivy','Bob','Tom','Jay','Dan','Tom','Dan']

  array.reverse();
  console.log(array);//['Dan','Tom','Jay','Tom','Bob',]

  array.sort();
  console.log(array);//['Bob','Dan','Ivy','Jay','Tom','Tom']

  array.copyWithin(4,0,2);
  console.log(array);//['Bob','Dan','Ivy','Jay','Bob','Dan']

  array.fill('Tom',3,5);['Bob','Dan','Ivy','Tom','Tom','Dan']
  console.log(array);//

  console.log(array.pop());//Dan
  console.log(array);//['Bob','Dan','Ivy','Tom','Tom']

  console.log(array.shift());//Bob
  console.log(array);//['Dan','Ivy','Tom','Tom']

  console.log(array.splice(2,2,'Kim'));//['Tom','Tom']
  console.log(array);//['Dan','Ivy','Kim']

}