简体   繁体   中英

How we can pop element from one table and push the same element in other table when i click the submit button in Javascript?

I am new in javascript. So, I need to help.

Blockquote

var fruits = ["mango","apple","orange","kiwi"]

Blockquote

This is my array. I have two box in HTML. In One box there are one array which holds 4 Element and In Second box there is also An Empty Array.

Now when , I can perform onclick function on that time One element Pop from one box and push the same Element in other box at same time.

And Also i want to move all elements one by one. not all elements move in single click.

I want to move all elements in other box in 4 click, because of there are 4 Elements in array. So Every time i want to pop one element and Push 1 element in other.

So, Now How can i Perform this Push-pop operation in JavaScript. I really have no idea about this. Please help. Thanks in Advance..!!!

Try this, pop removes the last one from an array and returns it. Push adds to the end of an array. Put together you can remove an item from ine array and add to a different one in one statement.

var fruits = ["mango","apple","orange","kiwi"];
var emptyArray = [];

emptyArray.push(fruits.pop());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM