javascript - Why is the following map function returning the strings with commas? -


i'm looping through object. if 1 of keys matches value of fields object return value of type of fields object:

// objects  user: {   email: '',   password: '' }  formfields: [   { name: 'email', type: 'text', required: true },   { name: 'password', type: 'password', required: true } ]  // html  <input :type="getproptype($key)"  // function  getproptype (key) {   console.log(this.fields)   console.log(key)   return this.fields.map(field => {     if (field.name === key) return field.type   }) } 

it works except comma returned every field.type:

enter image description here

which strange since logs don't output commas:

enter image description here

what cause?

i think trying extract type of object same name value of key, in case more appropriate solution - ie find element given name extract type

getproptype(key) {   console.log(this.fields)   console.log(key);   var type;   this.fields.some(field => {     if (field.name === key) {       type = field.type;       return true;     }   });   return type } 

if want use .map(), then

return this.fields.filter(field => field.name === key).map(field => field.type).join('') 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -