0
0

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 3 years have passed since last update.

JQueryのextendメソッド

Posted at

#JQueryのextendメソッド(備忘録)

オブジェクトのマージにはextend()を使用する。

var obj1 = {name: "taro", age: 20};
var obj2 = {age: 25, sex: "man"};

$.extend(obj1, obj2);

console.log(obj1);

結果
{name: "taro", age: 25, sex: "man"}

第一引数に空オブジェクトを指定すると元オブジェクトを壊さずに済む。

var obj1 = {name: "taro", age: 20};
var obj2 = {age: 25, sex: "man"};

var newObj = $.extend({}, obj1, obj2);

console.log(obj1);
console.log(nowObj);

結果
{name: "taro", age: 20}
{name: "taro", age: 25, sex: "man"}
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?