[image] argisht333:
My question is : why doesn’t myArray stay =[[“John”, 23], [“cat”, 2]];
Because you are using the pop method
const removedElement = myArray.pop();
Here pop not only returns the element to the removedElement it removed from myArray, but pop also mutates the array or modifi… Answer from Cody_Biggs on forum.freecodecamp.org
W3Schools
w3schools.com › python › ref_list_pop.asp
Python List pop() Method
Note: The pop() method returns removed value. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › pop
Array.prototype.pop() - JavaScript | MDN
The pop() method of Array instances removes the last element from an array and returns that element. This method changes the length of the array.
Basic JavaScript - Manipulate Arrays With pop Method
Tell us what’s happening: My question is : why doesn’t myArray stay =[[“John”, 23], [“cat”, 2]]; I mean we do the .push() step, but doesn’t it only relate to removedFromMyArray? It’s like the same as I write “const removedFromMyArray = [“cat”, 2]”; so why does this has ... More on forum.freecodecamp.org
Javascript array pop() function
In the following example i have used the following code but its not working. const myArray =[[“John”, 23], [“cat”, 2]]; i was ask to make myArray equals [[“John”, 23]]; after using pop() function on myArray . then make const removedFromArray equals [[“cat”, 2]]; Your code so ... More on forum.freecodecamp.org
Array.pop - last two elements - JavaScript - Stack Overflow
I have a question using Array.pop function in JavaScript. Array.pop removes and returns the last element of an Array. My question is then: is it possible to remove and return the last TWO elements of More on stackoverflow.com
The four common Javascript array methods Push, Pop, Shift and Unshift
Great article! I think it’s important to note that working with the end of the array (push/pop) is more performant than the beginning (shift/unshift). The reason for this is that the array is indexed, so adding to the end of the array doesn’t require any additional time. Shift/unshift though require the whole array to be reindexed since you’re adding to the beginning. Performance isn’t important while you’re learning, and really only matters with large arrays, but it is a good concept to get used to early on. In programming, that’s noted with something called big O notation, which is just a formalized way to loosely note what’s going on in the code. Push/pop are what’s known as O(1)—pronounced “O of 1”—which means that it’s constant time, or the time of the method will always take the same amount of time no matter the length of the array. Shift/unshift are O(n)—pronounced “O of n”—which means that the length of time it takes depends on the number of items in the array. This isn’t to say that shift/unshift are bad. They are useful! Use them as you will. Write first, and then optimize later. More on reddit.com
Videos
01:05
pop Array Method | JavaScript Tutorial - YouTube
02:22
JS Array Methods Explained #7 - POP Method - YouTube
02:46
Push and pop array methods in Javascript tutorial - YouTube
01:49
Easily Understand pop() - A JavaScript Array Method - YouTube
00:58
Array.pop() and Array.shift() in JavaScript - YouTube
00:52
JavaScript Array pop() method - JavaScript Tutorial for Beginners ...
W3Schools
w3schools.com › jsref › jsref_pop.asp
JavaScript Array pop() Method
The pop() method removes (pops) the last element of an array.
Rolling Stone
rollingstone.com › music › music-news › neil-sedaka-dead-obituary-1235522925
Neil Sedaka, a Pop Hitmaker Across Two Eras, Dead at 86
6 hours ago - Sedaka did enjoy one more revival of sorts, when he started recording and sharing performances from home during the Covid-19 pandemic. The octogenarian proved adept at navigating this new era of short form video. He continued to post after the pandemic, sharing an array of new clips and archival ones on TikTok and Instagram.
Stack Overflow
stackoverflow.com
Stack Overflow: Newest Questions
I have an JavaScript array like this: let myArray = [ { name: 'Alice', children: ['Bob', 'Bill'] }, { name: 'Bob', children: 'Cindy' }, { name: 'Bill', children: [] }, { name: 'Cindy', ...
Mimo
mimo.org › glossary › javascript › array-pop
JavaScript Array pop() method: Syntax, Usage, and Examples
The pop() method in JavaScript removes the last element from an array and returns that element. It changes the original array by reducing its length by one. The JavaScript array pop method is often used when working with stacks, where the last item added is the first one removed (LIFO – Last ...
W3Schools
w3schools.com › js › js_array_methods.asp
JavaScript Array Methods
Shifting is equivalent to popping, but working on the first element instead of the last. The shift() method removes the first array element and "shifts" all other elements to a lower index.
freeCodeCamp
forum.freecodecamp.org › javascript
Javascript array pop() function - JavaScript - The freeCodeCamp Forum
October 12, 2022 - In the following example i have used the following code but its not working. const myArray =[[“John”, 23], [“cat”, 2]]; i was ask to make myArray equals [[“John”, 23]]; after using pop() function on myArray . then make const removedFromArray equals [[“cat”, 2]]; Your code so far can’t solve this i need help my code so far: const myArray = [[“John”, 23], [“cat”, 2]]; var ab = myArray.pop(); var removedFromMyArray = myArray.pop();
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
1 week ago - Note: pop() can only be used to remove the last item from an array.
GitConnected
levelup.gitconnected.com › pop-and-push-learning-javascripts-array-methods-by-building-them-fed7096cf6f0
pop and push: Learning Javascript’s Array Methods by Building Them | by Zakk Fleischmann | Level Up Coding
February 3, 2021 - A Slice in Go is a data structure equivalent to an Array in JavaScript, where an Array in Go acts like the more traditional Array-type. Arrays in Go have a fixed length that can’t be changed after initialization. Otherwise, I haven’t heard a good mnemonic for remembering the difference. At any rate, I can really simplify the implementation of my pop method by using slice:
Top answer 1 of 5
16
Split the array, use Array#slice to get the last two elements, and then Array#join with slashes:
var url = 'www.example.com/products/cream/handcreamproduct1';
var lastTWo = url
.split("/") // split to an array
.slice(-2) // take the two last elements
.join('/') // join back to a string;
console.log(lastTWo);
2 of 5
1
I love the new array methods like filter so there is a demo with using this
let o = 'www.example.com/products/cream/handcreamproduct1'.split('/').filter(function(elm, i, arr){
if(i>arr.length-3){
return elm;
}
});
console.log(o);