Skip to content

Tag: arrays

Why is my v-for statement not reacting to Vue properly?

I have the following code with marker-popup defined here: pointsArray is updated here: However, it does nothing to affect the v-for statement. Whenever the addPoint() method runs, it alters pointsArray in one of two ways It pushes to the array – this works fine, v-for is perfect It changes an element in…

Get the first and last item in an Array – JS

I am trying to get the first and last item in array and display them in an object. What i did is that I use the first and last function and then assign the first item as the key and the last item as the value. however this one gets me into trouble. It says undefined. Any idea why is

Can I create an object without a name in JS?

I have a structure that looks like this: I can iterate over them in a loop like this: Do I assume correctly that in the cards array I have a couple of objects without names? If so, how can I push more objects like that to the cards array without giving them names? I want to create those objects in

Using reduce() to find min and max values?

I have this code for a class where I’m supposed to use the reduce() method to find the min and max values in an array. However, we are required to use only a single call to reduce. The return array should be of size 2, but I know that the reduce() method always returns an array of size 1. I’m

use Lodash to sort array of object by value

I am trying to sort an array by ‘name’ value (using Lodash). I used the Lodash docs to create the solution below however .orderBy doesn’t seem to be having any affect at all. Can anyone shed some light on the correct way to sort array? Chars Array Function Code Answer This method orderBy doe…

Create object from array

I want to create an object from a list inside an array. I have an array which is dynamic and supposed to look like this: var dynamicArray = [“2007”, “2008”, “2009”, “2010”]; And I want to make an object like this with some JavaScript ES6: Don’t worry about…

Grouping array of objects by multiple keys

I feel embarrassed for asking this question as I should know how to figure it out, but I’m spinning my wheels on grouping an array of objects by multiple keys. Here’s the data: What I’ve been trying to generate with little success is the following: The schema is: I’ve tried the followi…

Vue.js – components data do not update

I have a Vue list that is based of an array and each array item renders a component where I bind the array item properties. This component has a mixed data, based on the binded properties The problem is that when I change the initial list array in any way, the mixed prop of the component maintains it’s …