Karteikarten
Javascript methods
Karten in diesem Stapel (4)
- 1What is the difference between the slice( ), splice( ), & split( ) methodsThe slice( ) method copies a given part of an array and returns that copied part as a new array. It doesn’t change the original array.
array.slice(from, until);
The splice( ) method changes an array, by adding or removing elements from it. Let’s see how to add and remove elements with splice( ):
array.splice(index, number of elements);
array.splice(2);
The split( ) method is used for strings. It divides a string into substrings and returns them as an array. It takes 2 parameters, and both are optional.
string.split(separator, limit); - 2What is the difference between call and apply?The difference is that apply lets you invoke the function with arguments as an array; call requires the parameters be listed explicitly. A useful mnemonic is "A for array and C for comma."
Pseudo syntax:
theFunction.apply(valueForThis, arrayOfArgs)
theFunction.call(valueForThis, arg1, arg2, ...) - 3What is the difference between forEach(..), every(..), and some(..)forEach(..) will iterate over all values in the array, and it ignores any callback return values. every(..) keeps going until the end or the callback returns a false (or “falsy”) value, whereas some(..) keeps going until the end or the callback returns a true (or “truthy”) value.
- 4What is the difference between Object.keys(..) and Object.getOwnPropertyNames(..)Object.keys(..) returns an array of all enumerable properties, whereas Object.getOwnPropertyNames(..) returns an array of all properties,enumerable or not.
Informationen
- Beschreibung
- Javascript Karteikarten am Javascript methods, erstellt von Ben Parish am 29/05/2019.
- Erstellt von
- Ben Parish
- Aufrufe
- 1
- Bewertung