question

José avatar image
José asked

Localisation & array

Hi everyone!!!

I have the next issue; my alexa's skill have a file localisation.js to manage the language, into it i have an array like this:

 questions: [
'question 1',
'question 2',
'question 3',
'question 4'
]

How i can do to get questions size (number of indexes) in index.js to asingation??

i tried

 const quizSize = 'questions'.length

but i get the size of questions like string.

Thanks a lot for read and answer.


alexa skillsalexa hosted skillslocales
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy Whitworth avatar image
Andy Whitworth answered

Remove the quotes:

const quizSize = questions.length;

With the quotes, you're getting the length of the string 'questions' as you've found.

5 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

José avatar image José commented ·

I already tried that Andy. if i remove quotes, get this:


captura-de-pantalla-2021-11-09-a-las-141445.jpg


thanks anyway...

0 Likes 0 ·
Andy Whitworth avatar image Andy Whitworth José commented ·
Where did VAL_REL come from ? In your first post the variable was named questions.

Where have you defined VAL_REL in your code ?

0 Likes 0 ·
José avatar image José Andy Whitworth commented ·

ok np, questions or VAL_REL, both are arrays, called from localisation.js file. I need get them size.

0 Likes 0 ·
Show more comments
José avatar image
José answered

I got it!!! it was only necessary to implement the following function to retrieve the array as an object and then obtain its size.

in index.js:

function r(template) {
  return i18n.t(template, { returnObjects: true });
}


To get the array size:

quizSize = r('questions').length;
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

José avatar image
José answered

Thanks Andy.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.