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

LIFO(後入れ先出法)

Posted at

LIFOという後入れ先出し法(last in first out)
javascriptの配列要素の取り出し方法

最後の格納(push)したデータから取り出される方法

この方法を学ぶために
pop()=配列の最後の要素を取り出すメソッド
が重要になる

例🔻

var ary=['aa','bb','cc'];

ary.push('dd');
document.write('ary='+ ary + '<br>');  //ary=aa,bb,cc,dd

var pop1=ary.pop();
document.write('pop1=' + pop1 + '<br>'); //pop1=dd
document.write('ary=' + ary + '<br>');  //ary=aa,bb,cc

var pop2 = ary.pop();
document.write('pop2=' + pop2 + '<br>'); //cc
document.write('ary=' + ary + '<br>');  //aa,bb

ary.push('zz');
document.write('ary=' + ary + '<br>');   //aa,bb,zz

LIFOの使い方として、履歴の管理が代表的であるらしい。
戻るボタンをクリックすると、最後に追加された履歴のページから順に表示される方法が、LIFOのやり方で実現できるとの事。

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?