Esperando

quem tanto vem e vai. “Esperando” is published by Jailson Izidório.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Javascript array methods

A Javascript array is defined by MDN as a “list-like object whose prototype has methods to perform traversal and mutation operations”. In layman's terms, w3schools defines them as “special variables that are used to store multiple values”. They can also hold any kind of data type (numbers, strings, objects, booleans + symbols).

Filter method: creates a new array filled with only the array elements that pass a test (provided as a function). Doesn’t change the original array.

This would return a new array called filteredFruits that now only contains “apples” and “bananas” because their string lengths are both bigger than 5. “pears” is not included because it's only equal to 5.

Map method: creates a new array filled with the results of calling a function for every array element. This method iterates over the entire array and calls the provided function once for each element in an array, in order. Doesn’t change the original array.

This would return a new array called mappedFruits that now contains “APPLES”, “BANANAS” and “PEARS” as the function has converted every string in the array to upper case letters.

Find method: creates a new array filled with the value of the first element in an array that passes a test. Doesn’t change the original array.

Includes method: determines whether a string contains the characters of a specified string. This method returns true if the string contains the characters, and false if not. This method is case sensitive.

This would return a new array called findFruits that now contains “pears” only as this is the only string in the array that includes the lowercase letter p. If there was another string in the array after “pears” that also included “p”, the array would still only contain “pears” because it only returns the first matching element.

These are only a few but some other cool Javascript array methods to look into might be:

Add a comment

Related posts:

Bitcoin Red Diamond Will Become Global Payment.

Bitcoin Red Diamond is a peer-to-peer crypto currency and can be termed as a modified version of the technology on which bitcoin was built. BRD Specifics Acceleration: With BRD’s proprietary 3SPoS…

The Last Act

A well rehearsed play — you set the stage Me in the foreground, her in the center You’ve saved the best lies for me the pretense creates a satire a parody of four lives You and I satisfied at their…

ATP Tennis 2018 June 5 FRENCH OPEN

A beauty day. Called every match perfectly, albeit, I admit, that Diego/KA over did not look promising after the second set. Or really at any point in the third set… or really , at any point in the…