
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- How to convert an array into JavaScript string?
- Join Map values into a single string with JavaScript?
- How to convert list elements into a single string in R?
- Convert array into array of subarrays - JavaScript
- C# program to convert several strings into a single comma-delimited string
- How to convert an array into a complex array JavaScript?
- How to convert a string into integer in JavaScript?
- How to convert a JSON string into a JavaScript object?
- Convert JS array into an object - JavaScript
- How to store query result (a single document) into a variable?
- Convert nested array to string - JavaScript
- How convert an array of Strings in a single String in java?
- How to merge objects into a single object array with JavaScript?
- Convert integer array to string array in JavaScript?
- How to convert a string into upper case using JavaScript?

Advertisements