(ง •̀_•́)ง Ming and Her Code

References

Content

Object

hasOwnProperty

const object1 = new Object();
object1.property1 = 42;
console.log(object1.hasOwnProperty("property1")); // expected output: true
console.log(object1.hasOwnProperty("toString")); // expected output: false
console.log(object1.hasOwnProperty("hasOwnProperty")); // expected output: false

String and Array

includes

//string
var sentence = "The quick brown fox jumps over the lazy dog.";
var word = "fox";
console.log(`The word "${word}" ${sentence.includes(word) ? "is" : "is not"} in the sentence`);
// expected output: "The word "fox" is in the sentence"
//array
var array1 = [1, 2, 3];
console.log(array1.includes(2)); // expected output: true
var pets = ["cat", "dog", "bat"];
console.log(pets.includes("cat")); // expected output: true
console.log(pets.includes("at")); // expected output: false

String

endsWith

const str1 = "Cats are the best!";
console.log(str1.endsWith("best", 17)); // expected output: true
const str2 = "Is this a question";
console.log(str2.endsWith("?")); // expected output: false

startsWith

const str1 = "Saturday night plans";
console.log(str1.startsWith("Sat")); // expected output: true
console.log(str1.startsWith("Sat", 3)); // expected output: false

Array

every

function isBelowThreshold(currentValue) {
 return currentValue < 40;
}
var array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold)); // expected output: true

some

var array = [1, 2, 3, 4, 5];
var even = function(element) {
 // checks whether an element is even
 return element % 2 === 0;
};
console.log(array.some(even)); // expected output: true