16
14

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.

【jQuery】jQueryオブジェクトから配列の取得

Last updated at Posted at 2015-04-19

get()や$.makeArray()でjQueryオブジェクトから配列を取得できる。
取得後は配列なので、jQueryオブジェクトでは使用できなかった.pop()や.reverse()やjoin()が使えるようになる。

対象のhtml
<p>aaa</P>
<p>bbb</P>
<p>ccc</P>
配列に変換される箇所
console.log($('p'));

/*get()や$.makeArray()では0,1,2の部分が配列として取得できる。
0: p
1: p
2: p
context: document
length: 3
prevObject: jQuery.fn.jQuery.init[1]
selector: "P"
__proto__: jQuery[0]
*/

##get()

$array = $('p').get();
console.log($array);
/*
0: p
1: p
2: p
*/

##$.makeArray()

$array = $.makeArray($('p'));
console.log($array);
/*
0: p
1: p
2: p
*/
16
14
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
16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?