Thursday, November 12, 2020

Arrays 2 : Static Methods Array.of() Array.from() Array.isArray() Object.entries() Object.keys() Object.value()

Array.of() Array.from() Array.isArray() Object.entries() Object.keys() Object.value()


// Array.of(); // Make an array from its arguments

// Array.of('Wes', 'Kait');
// Make an array from a String or Iterable.

// How to create a Range from x to y:

function createRange(start, end) {
const range = Array.from({ length: end - start + 1}, function(_item, index) {
return index + start;
})
return range;
}

// Make a function that creates a range from x to y with Array.from();
const myRange = createRange(3, 7424);

// Check if the last array you created is really an array with Array.isArray();
console.log(Array.isArray(myRange));

// Take the meats object and make three arrays with Object.entries(), Object.keys, Object.values()

// console.log(Object.entries(meats));
// console.log(Object.keys(meats));
// console.log(Object.values(meats));

//This one is already destructured:
Object.entries(meats).forEach(([key, value]) => {
// const key = entry[0];
// const value = entry[1];
// const [key, value] = entry;
 console.log(key, value);
});

No comments:

Post a Comment

Arrays 4 : Callback Methods find() filter() some() every() sort()

  /* Callback Methods */ // const util = { // findBurgRating: function(singleFeedback) { // return singleFeedback.comment....