Created by James Drummond
almost 9 years ago
|
||
Question | Answer |
How do you insert a character into a string in Javascript? | Remember that Javascript strings are immutable var myStr = 'hi there'; var newString = myStr.subStr(0, i) + 'u' + myStr.subStr(i + 1); |
How do you remove an item from the beginning of an array? | var fruits = ["Apple", "Banana"]; fruits.shift(); |
How do you add an item to the beginning of an array? | fruits.unshift('banana') |
How do you find the index of an item in an array? | var fruits = ["Apple", "Banana", "mango"]; var index = fruits.indexOf('mango'); |
How do you remove an item from an array? | var pos = 1; var removedItem = fruits.splice(pos, 1); // Remove one item from position one |
What does splice() do? | Splice changes an array by removing elements and / or adding new ones |
How would you remove two elements from a given index in an array? | var arr = ['mango', 'banana', 'orange']; var removed = arr.splice(1, 2); // Removes two elements from the array starting at position 1 |
What is the difference between slice and splice? | Slice returns a portion of an array. Splice modifies the array |
How do you test if an object is an array? | var myArr = []; Array.isArray(myArr) (IE9+) ** Note syntax. You don't call this on the array directly!** |
How do you change a string to uppercase in Javascript? | var newString = 'myString'.toUpperCase(); |
What does Array.map() do? | The map method creates a new array with the results of performing a function on an old array. |
What does Array.from() do? | Creates a new array from an 'array like' or iterable object. |
What does Array.reduce() do? | Iterates the array and applies a function to the previously calculated and current value to reduce the array to a single value |
What does Array.filter() do? | Removes an item from an array (IE9 +) |
Can you subclass an Array? | You can in ES6, otherwise no. |
Want to create your own Flashcards for free with GoConqr? Learn more.