Help with concatenating

1

I need to pass a variable inside an array of items, a parameter that only accepts string, but when I pass a variable the API does not accept, it says the parameter is incorrect.

Better explaining:

 var userstocreate = [
 {
     username: 'aqui a variavel',
     password: 'senha',
     firstname: 'nome',
     lastname: 'sobrenome',
     email: 'email'
 }

In the username where the 'variable is here' I have to enclose it in single quotes.

Does anyone have a light to do this?

I did it, thanks for the help everyone was like.

   var userstocreate = [
   {
    username: '' + usuario + '',
    password: 'E@d123456',
    firstname: '' + primeiro +'',
    lastname: '' + lastname + '',
    email: '' + email + ''
   }
 ];

var primeiro = this.firstname.toString();
var usuario = this.username.toString();
var lastname = this.lastname.toString();
var email = this.email.toString();
    
asked by anonymous 19.11.2015 / 12:01

2 answers

0

Try to use escape characters like \' to first get the value of the variable and make it a string

username: "\'"+ variavel +"\'",
    
19.11.2015 / 12:09
0

I honestly did not understand. Do you want the username to have a value of a variable?

If so, you have a lot to do.

var akira = "texto"

example;

var userstocreate = [
    {
        username: akira,
        password: 'senha',
        firstname: 'nome',
        lastname: 'sobrenome',
        email: 'email'
    }
]

or

var userstocreate = [
    {
        username: '', //opcional definir
        password: 'senha',
        firstname: 'nome',
        lastname: 'sobrenome',
        email: 'email'
    }
]
userstocreate[0].username = akira
    
19.11.2015 / 12:16