Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

append to array check if exists javascript

var array = ['test1','test2'];
var item = 'test2';

if(array.indexOf(item) === -1) {
    array.push(item);
}
// array = ["test1", "test2"]

if(array.indexOf(item) !== -1) {
    array.push(item);
}
// array = ["test1", "test2", "test2"]
 
PREVIOUS NEXT
Tagged: #append #array #check #exists #javascript
ADD COMMENT
Topic
Name
1+4 =