-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"
    }
];
0

1 Answer 1

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")

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.