JavaScript Array Reference #1 — Quick Learn

Bayram EKER
3 min readOct 24, 2022

--

I am sharing a series of articles that will tell JavaScript topics quickly and fluently.

1-) concat()

The concat() method concatenates (joins) two or more arrays.

var newarray = ["birinci", "ikinci", "ucuncu"]
var oldArray = ["extra", "bosver", "kazanım"]
var children = newarray.concat(oldArray)
console.log(children)

Output: [ ‘birinci’, ‘ikinci’, ‘ucuncu’, ‘extra’, ‘bosver’, ‘kazanım’ ]

2-) constructor

The constructor property returns the function that created the Array prototype.

var meyve = ["elma","armut","kayısı"]
console.log(meyve.constructor)

Output: [Function: Array]

3-) copyWithin()

The copyWithin() method copies array elements to another position in the array.

array.copyWithin(target, start, end)
copyWithin(sol,sag) : sağdaki indisi soldaki indise kopyala
var meyve = ["elma","armut","kayısı"]
console.log(meyve.copyWithin(1,0))

Output: [ ‘elma’, ‘elma’, ‘armut’ ]

4-) entries()

The entries() method returns an Array Iterator object with key/value pairs

The entries() method does not change the original array.

var meyve = ["elma","armut","kayısı","muz","kivi"]
var arrayIterator = meyve.entries();
for (var x of arrayIterator){
console.log(x)
}

Output ->

[ 0, ‘elma’ ]
[ 1, ‘armut’ ]
[ 2, ‘kayısı’ ]
[ 3, ‘muz’ ]
[ 4, ‘kivi’ ]

5-) every()

The every() method executes a function for each array element.

The every() method returns true if the function returns true for all elements.

var yaslar = [19,17,24,45,66]
console.log(yaslar.every(yasKontrol))
function yasKontrol(yas){
return yas > 18
}

Output : false

6-) fill()

The fill() method fills specified elements in an array with a value.

a-)

var meyve = ["elma","armut","kayısı","muz","kivi"]
console.log(meyve.fill("ananas"))

Output : [ ‘ananas’, ‘ananas’, ‘ananas’, ‘ananas’, ‘ananas’ ]

b-)

var meyve = ["elma","armut","kayısı","muz","kivi"]
console.log(meyve.fill("ananas", 0, 3))

Output : [ ‘ananas’, ‘ananas’, ‘ananas’, ‘muz’, ‘kivi’ ]

7-) filter()

The filter() method creates a new array filled with elements that pass a test provided by a function.

var yaslar = [19,17,24,45,66]
console.log(yaslar.filter(arrayFilter))
function arrayFilter(yas){
if (yas > 18)
return yas
}

Output : [ 19, 24, 45, 66 ]

8-) find()

The find() method returns the value of the first element that passes a test.

var yaslar = [19,17,24,45,66]
console.log(yaslar.filter(arrayFilter))
function arrayFilter(yas){
if (yas > 18)
return yas
}

Output : [ 19, 24, 45, 66 ]

9-) forEach()

The forEach() method calls a function for each element in an array.

// Arrow function
forEach((element) => { /* … */ })
forEach((element, index) => { /* … */ })
forEach((element, index, array) => { /* … */ })

var meyve = ["elma","armut","kayısı","muz","kivi"]meyve.forEach(elements => console.log(elements))

Output :

elma
armut
kayısı
muz
kivi

10-) Array.from()

The Array.from() method returns an array from any object with a length property.

var textDeger = "ABCDEF"console.log(Array.from(textDeger))

Output : [ ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’ ]

11-) includes()

The includes() method returns true if an array contains a specified value.

var meyve = ["elma","armut","kayısı","muz","kivi"]console.log(meyve.indexOf("elma"))

Output : 0

12-) isArray()

The isArray() method returns true if an object is an array, otherwise false.

var meyve = ["elma","armut","kayısı","muz","kivi"]console.log(Array.isArray(meyve))

Output : true

13-) join()

The join() method returns an array as a string.

var meyve = ["elma","armut","kayısı","muz","kivi"]console.log(meyve.join())

Output : elma,armut,kayısı,muz,kivi

Thank you for reading this article.

If you find this article useful please kindly share it with your network and feel free to use the comment section for questions, answers, and contributions.

You might also like :

--

--