How to divide the information of an array and send it to another array? [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Group by element in array by keyword
3 answers
I have this array in Javascript:
cars = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari},
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:
I want to separate ferraris cars from Toyota
carsseparated[0] = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari}
]
carsseparated[1] = [
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
this is what I have been coding
$scope.carsseparated= ;
var cont = 0;
$.each($scope.cars, function (index,value) {
$scope.carsseparated[cont] = [value.color, value.type, value.name]
cont = cont+1;
}
javascript jquery arrays angularjs
marked as duplicate by Ori Drori
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 15:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Group by element in array by keyword
3 answers
I have this array in Javascript:
cars = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari},
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:
I want to separate ferraris cars from Toyota
carsseparated[0] = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari}
]
carsseparated[1] = [
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
this is what I have been coding
$scope.carsseparated= ;
var cont = 0;
$.each($scope.cars, function (index,value) {
$scope.carsseparated[cont] = [value.color, value.type, value.name]
cont = cont+1;
}
javascript jquery arrays angularjs
marked as duplicate by Ori Drori
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 15:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Group by element in array by keyword
3 answers
I have this array in Javascript:
cars = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari},
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:
I want to separate ferraris cars from Toyota
carsseparated[0] = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari}
]
carsseparated[1] = [
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
this is what I have been coding
$scope.carsseparated= ;
var cont = 0;
$.each($scope.cars, function (index,value) {
$scope.carsseparated[cont] = [value.color, value.type, value.name]
cont = cont+1;
}
javascript jquery arrays angularjs
This question already has an answer here:
Group by element in array by keyword
3 answers
I have this array in Javascript:
cars = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari},
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:
I want to separate ferraris cars from Toyota
carsseparated[0] = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari}
]
carsseparated[1] = [
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]
this is what I have been coding
$scope.carsseparated= ;
var cont = 0;
$.each($scope.cars, function (index,value) {
$scope.carsseparated[cont] = [value.color, value.type, value.name]
cont = cont+1;
}
This question already has an answer here:
Group by element in array by keyword
3 answers
javascript jquery arrays angularjs
javascript jquery arrays angularjs
edited Nov 23 '18 at 17:41
georgeawg
34.7k115470
34.7k115470
asked Nov 23 '18 at 15:21
TalkedTalked
205
205
marked as duplicate by Ori Drori
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 15:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ori Drori
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 15:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
add a comment |
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
add a comment |
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
{color: "red", type: "sedan", name: "toyota"}];
let car1 = cars.filter(val => val.name === 'ferrari');
let car2 = cars.filter(val => val.name === 'toyota');
console.log(car1)
answered Nov 23 '18 at 15:28
raviravi
25828
25828
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
add a comment |
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.
– Talked
Nov 23 '18 at 15:42
add a comment |