
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert JavaScript Array Iteration Result into a Single Line Text String
Let’s say, we have a string and an array −
const textString = 'Convert javascript array iteration result into a single line text string. Happy searching!'; const keywords = ['integer', 'javascript', 'dry', 'Happy', 'exam'];
We have to write a function that maps the array to a string containing only true and false depending on the fact whether the corresponding array element is present in the string or not.
Example
const textString = 'Convert javascript array iteration result into a single line text string. Happy searching!'; const keywords = ['integer', 'javascript', 'dry', 'Happy', 'exam']; const includesString = (arr, str) => { return arr.reduce((acc, val) => { return acc.concat(str.includes(val)); }, []).join(', '); }; console.log(includesString(keywords, textString));
Output
The output in the console will be −
false, true, false, true, false
Advertisements