As title, I am getting the result that I wanted from console.log(result), however, how can I pass this console.log result to the string variable and "return" it? I am having trouble returning the result of console.log(). Thanks!
var type = ["men","women","boys", "girls"]
var product = "women shoes";
product.split(' ').forEach(function(item){
type.forEach(function(elem){
if(elem==item){
console.log(elem);
}
});
});
Thank you for all the answers here, and it is so amazing that so many people are willing to help my beginner problem. Let me clear my question a little bit here, like above, console.log (elem) will return woman, however, if i replace the line concole.log(elem) with return(elem) will get me nothing. Why is that?
resultvariable in yourconsole.log()?console.logwill just print whatever value you pass it to the console. That same value is still available. Could you please create a MCVE to show us your problem?JSON.stringify()but once again, this question lack a lot of information.