I'm pretty sure that there is something similar, but I can't figure it out this one in my scope. I have an array, and I need to create another array based on an object (In this case, BannerAtivo: true).
My JSON:
[{
"BannerID": 0,
"BannerImage": "http://hotsite/example2.png",
"BannerMin": "http://hotsite/example.png",
"BannerTitulo": "Xurupita Style",
"BannerDesc": "Lorem Ipsum Dolor Siamet",
"BannerAtivo": false,
"SetorId": 1
}, {
"BannerID": 2,
"BannerImage": "http://hotsite/example2.jpg",
"BannerMin": "http://hotsite/example.jpg",
"BannerTitulo": "Chihuahua",
"BannerDesc": "Role",
"BannerAtivo": true,
"SetorId": 1
}]
I'm trying the following code:
var data = response.data;
$scope.banners = data;
var a = $scope.banners;
function check(a) {
return a.BannerAtivo = true;
console.log(BannerAtivo);
}
What I want is: Show it in my scope only the lists where in the object BannerAtivo is true. I have already tried filter, and couldn't figure out how to make it. I can't even show it on the console. I know this question is dumb, and yes, I'm pretty newbie in javascript and angular. Sorry.
= truenot a comparison. Use== trueor=== true$scope.banners = response.data.filter((banner) => banner.BannerAtivo);console.log(BannerAtivo)doesn't execute, you are exiting the function before it withreturn.