javascript - Unable to remove Value from Array in Jquery -


i have following array

var useridarray=["1", "3", "6", "39", "62", "139"]; 

i want remove array value using value

i have tried following method

function  deletemember(id) {                 alert(id+"="+useridarray.indexof(id));                  useridarray.splice(useridarray.indexof(id),1);              } 

but remove last value.

also noticed useridarray.indexof(id) return -1 if pass value useridarray.indexof("6") delete particular position can 1 me how remove particular value ?

i think got problem id putting deletemember functions isn't string.

this solve problem:

var useridarray=["1", "3", "6", "39", "62", "139"];    function  deletemember(id) {      removeid = string(id)      removeindex = useridarray.indexof(removeid)      if(removeindex != -1)       useridarray.splice(removeindex,1);  }    deletemember(3)  console.log(useridarray)

a more beautiful way handling data this: (es6 approach)

var useridarray=["1", "3", "6", "39", "62", "139"];    deletememberfromarray = (array, value) =>       array.filter((member) =>       	 member != string(value)      );      useridarray = deletememberfromarray(useridarray, 3)  console.log(useridarray)


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -