AnswerBun.com

how to find and remove array using jquery

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

One Answer

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

Add your own answers!

Related Questions

numpy array type not supported?

1  Asked on December 30, 2021 by user3066560

     

Angular Material not applying styles

1  Asked on December 30, 2021 by xeraphim

   

Calibrating undistortion reducing the size of image

1  Asked on December 30, 2021 by naga-kiran

       

Spring Boot @Component doesn’t create Beans

2  Asked on December 27, 2021 by bart-kosmala

     

How to declare a function using assignment operator?

2  Asked on December 27, 2021 by legendrary-saiyan

   

How can i get {{form}} value with javascript?

2  Asked on December 27, 2021 by user12584812

   

how to align image and label side by side in html?

3  Asked on December 27, 2021 by jeet-viramgama

   

Django no module named ‘main’

1  Asked on December 27, 2021 by seyed-moein-ayyoubzadeh

   

How to get the sum of the values of the JSON Array?

4  Asked on December 27, 2021 by iri0021

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir