JavaScript 3
JavaScript 3
JavaScript-3
- W3shools.com
Check Demo 11
var fruits =
["Banana", "Orange", "Apple", "Mango"];
console.log(Array.isArray(fruits));
Check Demo 12
function myFunction(value) {
txt = txt + value + "<br>";
console.log(txt);
}
Check Demo 13
The map() method does not execute the function for array elements
without values.
Check Demo 14
//Total here represents the initial value or the previously returned value
Check Demo 16
This example check if all array values are larger than 18:
This example check if some array values are larger than 18:
Check Demo 18
14 Web Technology Neamat El Tazi
Array.indexOf()
The indexOf() method searches an array for an element
value and returns its position.
Note: The first item has position 0, the second item has
position 1, and so on.
var fruits =
["Apple", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");
var fruits =
["Apple", "Orange", "Apple", "Mango"];
var a = fruits.lastIndexOf("Apple");
This example finds (returns the value of) the first element that
is larger than 18:
// Create an object:
var person = {
firstName: "John",
lastName : "Doe",
get fullName() {
return this.firstName + " " + this.lastName;
}
};
// Display data from the object using a getter:
document.getElementById("demo").innerHTML = person.fullName;
// Create an Object:
var person = {
firstName: "John",
lastName : "Doe",
language : "NO",
};
// Change a Property:
Object.defineProperty(person, "language", {
value: "EN",
writable : true,
enumerable : true,
configurable : true
});
// Enumerate Properties
var txt = "";
for (var x in person) {
txt += person[x] + "<br>";
}
document.getElementById("demo").innerHTML = txt;
"Hello \
Dolly!";
A safer way to break up a string literal, is to use
string addition:
"Hello " +
"Dolly!";