1

I'm trying to filter some JSON data to search for job roles that starts with a certain string.

The JSON looks like :

"periods": [
        {
            "periodName": "Week1",
            "teamName": "Tango",
            "roleName": "SoftwareEngineerII",
            "roleExperience": "2",
            "id": "cc1f6e14-40f6-4a79-8c66-5f3e773e0929"
        },
        ...
    ]

I want to filter for roleName that starts with "Software" so that I can see a list of all Software Engineer levels, and it filters out other roles.

I'm not sure how to do a "starts with" or "contains" here.

1

1 Answer 1

1

You are trying to filter the array where one of the string properties contains a value... How else would you check if a string contains another string?

You could use a regex:

var str = 'SoftwareEngineerII';
if (str.match(/^software/i)) {
    // it starts with 'software'
}

So you need to convert this to a predicate that could be used in your filter.

var query = Enumerable.From(data.periods)
    .Where("!!$.roleName.match(/^software/i)")
    .ToArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.