Google News
logo
UI Developer - Interview Questions
How would you filter an array of objects based on conditions using JavaScript?
We can do that using the “filter” function :
let data = [
  "files/dir1/file1",
  "files/dir1/file2",
  "files/dir2/file1",
  "files/dir2/file2"
];
let filteredData = data.filter(path => path.includes('dir2'));
console.log(filteredData);
--> [ 'files/dir2/file1', 'files/dir2/file2' ]​
Advertisement