js function in array code example
Example 1: javascript element in array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
Example 2: javascript array
const arr = [1, 2, 3];
Example 3: array methods in javascript
<script>
function getUnique(array){
var uniqueArray = [];
for(var value of array){
if(uniqueArray.indexOf(value) === -1){
uniqueArray.push(value);
}
}
return uniqueArray;
}
var names = ["John", "Peter", "Clark", "Harry", "John", "Alice"];
var uniqueNames = getUnique(names);
console.log(uniqueNames);
</script>
Example 4: array
const MyArray = {"Object1", "Object2", "Object3"};