Search
 
SCRIPT & CODE EXAMPLE
 

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"]
Comment

js push into array if item exist

if(this.items.indexOf(item) === -1) {
    this.items.push(item);
    console.log(this.items);
}
Comment

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)
Comment

js add to array if not exists

const key = 'mDisplayName'
let updatedData = [...new Map(data.map(item => [item[key], item])).values()];
updatedData.map((item)=>{
	console.log(item);
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: moving a item fro index to another index, javascript 
Javascript :: how to set text for label in jquery 
Javascript :: To set the text of button using Jquery 
Javascript :: v-for vue 
Javascript :: js are you sure alert 
Javascript :: firebase get current user javascript 
Javascript :: javascript upload json 
Javascript :: react native go to next text input 
Javascript :: how to get data from user in javascript 
Javascript :: sequelize find one 
Javascript :: javascript remove last child element 
Javascript :: redirect angular 
Javascript :: socket io emit from socket instance or server 
Javascript :: get value of element html js 
Javascript :: event listener for element lost focus 
Javascript :: js arrotondare numeri 
Javascript :: javascript unique array of objects by property 
Javascript :: set year in javascript 
Javascript :: javascript loop through object 
Javascript :: check length of number javascript 
Javascript :: jquery on click 
Javascript :: express draft 
Javascript :: adonis lucid join 
Javascript :: vue.js cdn 
Javascript :: javascript folder exists 
Javascript :: Nazmul 
Javascript :: regex min length max length 
Javascript :: jquery set value by id 
Javascript :: how to truncate string in javascript 
Javascript :: How to clear localStorage when browser/tab is closing 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =