How to add element to array if it does not exist in the array with TypeScript

1 Answer

0 votes
const arr = ['typescript', 'c', 'c++', 'python'];
const value = 'c#';
 
if (!arr.includes(value)) {
    arr.push(value);
}
 
 
console.log(arr);
 
   
   
   
   
/*
run:
   
["typescript", "c", "c++", "python", "c#"] 
   
*/

 



answered Apr 13, 2022 by avibootz
...