1

So I have a query in my mongoose schema which displays this in a resultArray

[
  { scholarship_type: 'Archer Achiever Scholarship' },
  { scholarship_type: 'Star Scholarship' },
  { scholarship_type: 'Star Scholarship' },
  { scholarship_type: 'Archer Achiever Scholarship' },
  { scholarship_type: 'Star Scholarship' },
  { scholarship_type: 'Archer Achiever Scholarship' }
]

I would like to convert this array to a substring which is

"Archer Achiever Scholarship, Star Scholarship, Star Scholarship, Archer Achiever Scholarship, Star Scholarship, Archer Achiever Scholarship"

Thank you so much in advance!

1 Answer 1

1

A simple way to do this in js: By using .map(), we iterate over the objects, and return the scholarship_type property. This gives us an array of strings containing the scholarship_type properties.


const scholarshipObjects = [{ scholarship_type: 'Archer Achiever Scholarship' },/*...*/]

const scholarshipsList = scholarshipObjects.map(
    (scholarship) => scholarship.scholarship_type
);
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.