0

I have the following index.js file;

var Lob = require('lob')('test_6afa806011ecd05b39535093f7e57757695');

var residence = require('./addresses.json');

console.log(residence.residence.length);

for (i = 0; i < residence.residence.length; i++) {
    console.log(residence.residence[i].name);

    Lob.addresses.create({
        name: 'residence.residence[i].name',
    }, function(err, res) {
        console.log(err, res);
    });
}

When I console.log( residence.residence[i].name ), the appropriate response "RESIDENT" appears.

However, I'm trying to pass in that same value as a value in the post request under Lob.addresses.create({ which isn't recognizing it.

How do I pass in that value into my key value pair as the value for "name:"?

1 Answer 1

3

It appears that you are passing in a literal String 'residence.residence[i].name' because of your use of quotes... Drop the quotes:

for (i = 0; i < residence.residence.length; i++) {
    console.log(residence.residence[i].name);

    Lob.addresses.create({
        name: residence.residence[i].name,
    }, function(err, res) {
        console.log(err, res);
    });

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.