-2

I am new to JavaScript and can't figure out how to do this. I tried using map and filter but could not able to put if condition. find the records in above array which has gender is 0 and color is red

let student = [
    {
        "ID": "1",
        "Name": "Senpai",
        "Gender": "1",
        "Class": "32",
        "Strength": "0",
        "Hairstyle": "1",
        "Color": "Black"
    },
    {
        "ID": "2",
        "Name": "Yui Rio",
        "Gender": "0",
        "Class": "11",
        "Strength": "0",
        "Hairstyle": "2",
        "Color": "Red"
    },
    {
        "ID": "3",
        "Name": "Yuna Hina",
        "Gender": "1",
        "Class": "12",
        "Strength": "0",
        "Hairstyle": "3",
        "Color": "Red"
    },
    {
        "ID": "4",
        "Name": "Koharu Hinata",
        "Gender": "0",
        "Class": "21",
        "Strength": "0",
        "Hairstyle": "4",
        "Color": "Green"
    },
    {
        "ID": "5",
        "Name": "Mei Mio",
        "Gender": "1",
        "Class": "22",
        "Strength": "0",
        "Hairstyle": "5",
        "Color": "Blue"
    }
];
Neha Verma
  • 11
  • 5

1 Answers1

0

const newArray = student.filter(s => { if(s.Gender === "0" && s.Color === "Red"){ return s } })

or

const newArray = student.filter(s => s.Gender === "0" && s.Color === "Red")