Answers for "filter by name"

1

filter return item name

Use .filter when you want to get the whole object(s) 
that match the expected property or properties.
Use .map when you have an array of things and want to 
do some operation on those things and get the result.

The challenge is to get all of the messages that are 50 
characters or less. So you can use filter to get only the 
messages that pass that test and then map to get only the 
message text.

function getShortMessages(messages) {
  return messages
    .filter(function(obj) {
      return obj.message.length <= 50;
    })
    .map(function(obj) {
      return obj.message;
    });
}
Posted by: Guest on April-30-2021

Browse Popular Code Answers by Language