Use three prompt boxes to ask the user for three different words and then place them in an array. Use an alert box to display the array

Advertisements So, I’m new to JS and currently taking courses. My instructor listed one solution, and the solution I came up with in my opinion is more ideal…I used push() method which I’d think is better. And I used Template literal inside my alert method to prevent the need to concat the string and variable….… Read More Use three prompt boxes to ask the user for three different words and then place them in an array. Use an alert box to display the array

Can't make array of arrays

Advertisements I’m trying to make an array of coordinate arrays, but I’m blanking out on how to doing. How do I make this happen? Code – targetLocations() { const data = [] const timer = setInterval(() => { for (let i = 0; i<store.state.location.locations.length; i++) { const coordinates = [store.state.location.locations[i]["longitude"]+","+store.state.location.locations[i]["latitude"]] data.push(coordinates) console.log("this is the data… Read More Can't make array of arrays

Filter Coordinate Array from Another Coordinate Array

Advertisements let big_coordinates_arr =[ [1,2],[3,4],[5,8],[7,9]] ; let small_coordinates_arr=[ [3,4],[7,9] ] ; Exepected Output: [ [1,2],[5,8] ] Dear all, is there a way to filter an array of coordinates from an array of coordinates? There are codes similar to this from element of array at here, but I am unsure on filtering 2d-nested array. I will… Read More Filter Coordinate Array from Another Coordinate Array

How to extract the middle item or (Two Items in Middle) from an array regardless of Odd or Even Number of Items?

Advertisements When I extract middle item from odd number of elements: var givenArray = [‘Maths’,’English’, ‘Social’, ‘Economics’,’Tech’] console.log(givenArray[((givenArray.length-1)/2)]) It provides output to be social which is what I am expecting but in case the number of items is even : var givenArray = [‘Maths’,’English’, ‘Social’, ‘Economics’] console.log(givenArray[((givenArray.length)/2)]) I get output Social. The actual question here… Read More How to extract the middle item or (Two Items in Middle) from an array regardless of Odd or Even Number of Items?

Array reduce explanation

Advertisements I would like to get some advise through javascript cookies handling. I have these code for extracting values from cookies.However i understand all the way till .map from .reduce array method i have some doubt. Can any body tell me what is happening through these method. Especially in .reduce((arg,[key,val])=> ({…arg,[key.trim()]:decodeURIComponent(val)}), {}); this line.And also… Read More Array reduce explanation

Intersection of 2 arrays containing objects

Advertisements I’m using the below code to intersect 2 very large arrays. Is it possible to improve the performance of this as it takes such a long time as it currently stands. const arr1 = [ { “number”:”123″, “firstName”:”John”, “lastName”:”Smith”, “email”:”test1@test.com”, }, { “number”:”1234″, “firstName”:”Chad”, “lastName”:”Baker”, “email”:”test2@test.com”, } ]; const arr2 = [ { “number”:”12345″,… Read More Intersection of 2 arrays containing objects