2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

javascript object 操作メモ

Last updated at Posted at 2012-12-26
appendHasAry
var tempObj = {Area:["tiyodaku","minatoku","tyuuouku"], range: "0km-10km"};
// 配列だった場合の追加の作法
if(tempObj.Area instanceof Array) {
  console.log( tempObj.Area.length + 'array' );
  tempObj.Area[tempObj.Area.length] = "add area";
  console.log( tempObj );
} else {
  console.log('tempObj.Area not array');
}

// 配列じゃなかった場合の追加の作法
if(tempObj.range instanceof Array) {
  console.log( tempObj.range.length + 'array' );
} else {
  console.log( tempObj.range + 'array' );
  tempObj.range = [tempObj.range,"add range"];
  console.log( tempObj );
}
2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?