[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
How expensive are push() and pop() array methods? Do they create a whole new array?
They don't create a new array. They mutate the original array in constant time. const nums = [1,2,3] nums.push(4). //nums now has [1,2,3,4] nums.pop() //nums now has [1,2,3] You can prevent mutation by using spread operator to create a new array out of original array in linear time. const newnums = [...nums,4] //newnums has [1,2,3,4] console.log(nums) //nums is still [1,2,3] Conclusion: imo both methods are fine, however you should use the immutable way if the array size is usually small and use the push pop way if the array size is too big. More on reddit.com
Videos
00:58
Array.pop() and Array.shift() in JavaScript - YouTube
02:22
JS Array Methods Explained #7 - POP Method - YouTube
01:49
Easily Understand pop() - A JavaScript Array Method - YouTube
01:05
pop Array Method | JavaScript Tutorial - YouTube
02:46
Push and pop array methods in Javascript tutorial - YouTube
00:52
JavaScript Array pop() method - JavaScript Tutorial for Beginners ...
Rolling Stone
rollingstone.com › music › music-news › neil-sedaka-dead-obituary-1235522925
Neil Sedaka, a Pop Hitmaker Across Two Eras, Dead at 86
1 day 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.
W3Schools
w3schools.com › jsref › jsref_pop.asp
JavaScript Array pop() Method
The pop() method removes (pops) the last element of an array.
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 ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
5 days 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);