js push into array if item exist
if(this.items.indexOf(item) === -1) { this.items.push(item); console.log(this.items); }
js push into array if item exist
if(this.items.indexOf(item) === -1) { this.items.push(item); console.log(this.items); }
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"]
js add to array if not exists
var newItem = "NEW_ITEM_TO_ARRAY"; var array = ["OLD_ITEM_1", "OLD_ITEM_2"]; array.indexOf(newItem) === -1 ? array.push(newItem) : console.log("This item already exists"); console.log(array)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us