简体   繁体   中英

a javascript app that return inputted word + words from a predefined word bank

I am trying to make an app that returns inputted word + words from a predefined word bank I have already made an input field and an output iframe and word bank

var bank =["Apples","Banana","Oranges","Grapes","Strawberry"] 

and a function to output

$("form").submit(function (e){
        e.preventDefault();
      var output = $(".output").contents().find("html").html($("#input").val());
});

but don't know how to add words to it

example:
User input: Delicious

App Returns:

Apples Delicious
Banana Delicious
Oranges Delicious
Grapes Delicious
Strawberry Delicious

my javascript and jquery skills aren't that great I just learned them about a month ago so help and thanks

You can use Array function called map()

var input = 'Delicious';

var delicious = bank.map(function(item) {
  return item + ' ' + input;
});

console.log(delicious);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM