1

I have an input field:

<input type="text" value="hello1,hello2" id="list">

I want to grab this value and turn it into an array (guessing .split() is the appropriate way):

var list = $('#list').val().split(",");

Now. How do I add add and element to this array? And how do I unset an array element? For example:

if (array_element == 'hello1') {
   // unset array_element
}
2
  • Add Concatenate the value. Remove Get value, split, filter, join, set value. Commented Jan 16, 2018 at 12:22
  • 1
    @Tushar Please post an answer with code examples. Thanks! Commented Jan 16, 2018 at 12:23

1 Answer 1

2

Add an item:

list.push('hello3');

Remove an item:

list.splice( $.inArray('hello1',list) ,1 );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.