Stack Overflow Asked by Sultan Achmad on December 13, 2020
how to retrieve data from an array list? then when the array data has been retrieved and displayed, the data will disappear from the array list.
var fruits = ["Banana", "Orange", "Watermelon"];
for example, I want to take a watermelon object. Then when I’ve retrieved that object, then I want to display it. after the watermelon object is displayed, the watermelon will disappear from the array list
If your goal is to retrieve an object by index and then to delete it you can do it like so:
function retrieve(array, index) {
return array.splice(index, 1)[0];
}
the splice function will take one (because of the second argument) element from the array and will return a new array with that item, then we access the first and only value of that array and return it.
Answered by Saar Davidson on December 13, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP