Quantcast
Channel: JavaScript filter method returning filtered array and empty array - Stack Overflow
Viewing all articles
Browse latest Browse all 3

JavaScript filter method returning filtered array and empty array

$
0
0

I am trying to log the current reading status but instead of getting just the log I am also getting an empty array when calling displayInformation(). How can I get the result I want without an additional empty array? and why is it returning an empty array?

function displayInformation() {  function statusRead(obj){    if (obj.readingStatus === false) {      console.log('You still need to read '+ obj.title +' by '+ obj.author +'.');    } else {      console.log('Already read '+ obj.title +' by'+ obj.author +'.');    }  }  var statusFilter = library.filter(statusRead);  console.log(statusFilter);}var library = [     {        title: 'Bill Gates',        author: 'The Road Ahead',        readingStatus: true    },    {        title: 'Steve Jobs',        author: 'Walter Isaacson',        readingStatus: true    },    {        title: 'Mockingjay: The Final Book of The Hunger Games',        author: 'Suzanne Collins',        readingStatus: false    }];displayInformation();

When you invoke displayInformation() this is whats logged to console

"Already read Bill Gates byThe Road Ahead.""Already read Steve Jobs byWalter Isaacson.""You still need to read Mockingjay: The Final Book of The Hunger Games by Suzanne Collins."[]

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images