How can I enter null values on indexes where 2 arrays don't match?How to insert an item into an array at a specific index (JavaScript)?How can I get query string values in JavaScript?How can I create a two dimensional array in JavaScript?How can I add a key/value pair to a JavaScript object?How do I check in JavaScript if a value exists at a certain array index?How to remove item from array by value?How do I check for null values in JavaScript?How can I shuffle an array?How can I add new array elements at the beginning of an array in Javascript?Get the index of the object inside an array, matching a condition

What is the meaning of "it" in "as luck would have it"?

Why did the Apple IIe make a hideous noise if you inserted the disk upside down?

Why didn't Caesar move against Sextus Pompey immediately after Munda?

Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?

How can this fractal shape perfectly cover a certain platonic solid?

Move up, right, left and down functions

Angle Between Two Vectors Facing A Point

Is there a word for the act of simultaneously pulling and twisting an object?

What is the lowest possible AC?

What prevents a US state from colonizing a smaller state?

Which high-degree derivatives play an essential role?

What does 'in attendance' mean on an England death certificate?

Converse of pumping lemma for regular expressions

What verb goes with "coup"?

Why is my 401k manager recommending me to save more?

Do electrons really perform instantaneous quantum leaps?

Did NASA distinguish between the space shuttle cockpit and flight deck?

How to count the number of bytes in a file, grouping the same bytes?

English idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)

Could you fall off a planet if it was being accelerated by engines?

Why doesn't SpaceX land boosters in Africa?

Understanding the as-if rule, "the program was executed as written"

What was the point of separating stdout and stderr?

Rear derailleur got caught in the spokes, what could be a root cause



How can I enter null values on indexes where 2 arrays don't match?


How to insert an item into an array at a specific index (JavaScript)?How can I get query string values in JavaScript?How can I create a two dimensional array in JavaScript?How can I add a key/value pair to a JavaScript object?How do I check in JavaScript if a value exists at a certain array index?How to remove item from array by value?How do I check for null values in JavaScript?How can I shuffle an array?How can I add new array elements at the beginning of an array in Javascript?Get the index of the object inside an array, matching a condition













1















I'm retrieving answers from the Typeform API. I'll put these answers into a dataset where the questions are the column names.
All of this works, untill a question isn't answered.
This doesn't return a null value.
For example:



Questions : [A, B, C, D]



Answers: [a, c, d] -> Question B didn't receive an answer.



I expect an output of [a, null, c, d] for above example.



I tried multiple ways to implement this in my code, but I don't find the right answer.



 let surveys = formsAnswer.items.map(survey => 
let i = 0
let lam = survey.answers.map(ans =>
let answ
let rightID2 = schema.map(findID =>
if (findID.id.toLowerCase() === req.body.id)
let id = findID.columnID[i]
i++
return id

)
switch (ans.type)
case 'boolean':
answ = ans.boolean ? 'Yes' : 'No'
break
case 'choice':
answ = ans.choice.label
break
case 'payment':
answ = parseFloat(ans.payment.amount) * 100
break
case 'empty':
answ = null
break
default:
answ = ans[ans.type]
break

return answ
)
return lam
)
return res.status(200).json(surveys)
})


In schema I have access to an array of all the question IDs from 1 form.



Thanks in advance!



EDIT 1
Example output of a survey with 10 questions.



 [
[["ZoW7FL2pVKvR","gfds"],
["amx5Q2JU4Qa7","Car 1"],
["jlqW0xFRGXdm","No"],
["FhfIURjvE8nN","dfs@hotmail.com"],
["vVTYmlvc1YIy",0]
["DqX2Dy0cvmMy","fezfze"]],

[["ZoW7FL2pVKvR", "Ruben"],
["ihNcWeYgZHPb","Male"],
["amx5Q2JU4Qa7","Car 2"],
["jlqW0xFRGXdm", "Yes"],
["FhfIURjvE8nN","ruben@gmail.com"],
["vVTYmlvc1YIy", 2],
["b8y0pDw3gYpn","No"],
["beeg0rtb7Mai","1995-02-10T00:00:00Z"],
["Knox8dyeM4Ak",10]]
]


This is the array of the all the questionIDs from 1 survey



"columnID": [
"ZoW7FL2pVKvR",
"ihNcWeYgZHPb",
"amx5Q2JU4Qa7",
"jlqW0xFRGXdm",
"FhfIURjvE8nN",
"vVTYmlvc1YIy",
"b8y0pDw3gYpn",
"beeg0rtb7Mai",
"Knox8dyeM4Ak",
"DqX2Dy0cvmMy"
]










share|improve this question
























  • I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

    – Wimanicesir
    Mar 25 at 15:58











  • The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

    – D.Dsn
    Mar 25 at 16:15











  • Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

    – Francis Leigh
    Mar 25 at 16:22











  • Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

    – Wimanicesir
    Mar 25 at 16:23











  • The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

    – Francis Leigh
    Mar 25 at 16:25















1















I'm retrieving answers from the Typeform API. I'll put these answers into a dataset where the questions are the column names.
All of this works, untill a question isn't answered.
This doesn't return a null value.
For example:



Questions : [A, B, C, D]



Answers: [a, c, d] -> Question B didn't receive an answer.



I expect an output of [a, null, c, d] for above example.



I tried multiple ways to implement this in my code, but I don't find the right answer.



 let surveys = formsAnswer.items.map(survey => 
let i = 0
let lam = survey.answers.map(ans =>
let answ
let rightID2 = schema.map(findID =>
if (findID.id.toLowerCase() === req.body.id)
let id = findID.columnID[i]
i++
return id

)
switch (ans.type)
case 'boolean':
answ = ans.boolean ? 'Yes' : 'No'
break
case 'choice':
answ = ans.choice.label
break
case 'payment':
answ = parseFloat(ans.payment.amount) * 100
break
case 'empty':
answ = null
break
default:
answ = ans[ans.type]
break

return answ
)
return lam
)
return res.status(200).json(surveys)
})


In schema I have access to an array of all the question IDs from 1 form.



Thanks in advance!



EDIT 1
Example output of a survey with 10 questions.



 [
[["ZoW7FL2pVKvR","gfds"],
["amx5Q2JU4Qa7","Car 1"],
["jlqW0xFRGXdm","No"],
["FhfIURjvE8nN","dfs@hotmail.com"],
["vVTYmlvc1YIy",0]
["DqX2Dy0cvmMy","fezfze"]],

[["ZoW7FL2pVKvR", "Ruben"],
["ihNcWeYgZHPb","Male"],
["amx5Q2JU4Qa7","Car 2"],
["jlqW0xFRGXdm", "Yes"],
["FhfIURjvE8nN","ruben@gmail.com"],
["vVTYmlvc1YIy", 2],
["b8y0pDw3gYpn","No"],
["beeg0rtb7Mai","1995-02-10T00:00:00Z"],
["Knox8dyeM4Ak",10]]
]


This is the array of the all the questionIDs from 1 survey



"columnID": [
"ZoW7FL2pVKvR",
"ihNcWeYgZHPb",
"amx5Q2JU4Qa7",
"jlqW0xFRGXdm",
"FhfIURjvE8nN",
"vVTYmlvc1YIy",
"b8y0pDw3gYpn",
"beeg0rtb7Mai",
"Knox8dyeM4Ak",
"DqX2Dy0cvmMy"
]










share|improve this question
























  • I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

    – Wimanicesir
    Mar 25 at 15:58











  • The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

    – D.Dsn
    Mar 25 at 16:15











  • Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

    – Francis Leigh
    Mar 25 at 16:22











  • Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

    – Wimanicesir
    Mar 25 at 16:23











  • The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

    – Francis Leigh
    Mar 25 at 16:25













1












1








1








I'm retrieving answers from the Typeform API. I'll put these answers into a dataset where the questions are the column names.
All of this works, untill a question isn't answered.
This doesn't return a null value.
For example:



Questions : [A, B, C, D]



Answers: [a, c, d] -> Question B didn't receive an answer.



I expect an output of [a, null, c, d] for above example.



I tried multiple ways to implement this in my code, but I don't find the right answer.



 let surveys = formsAnswer.items.map(survey => 
let i = 0
let lam = survey.answers.map(ans =>
let answ
let rightID2 = schema.map(findID =>
if (findID.id.toLowerCase() === req.body.id)
let id = findID.columnID[i]
i++
return id

)
switch (ans.type)
case 'boolean':
answ = ans.boolean ? 'Yes' : 'No'
break
case 'choice':
answ = ans.choice.label
break
case 'payment':
answ = parseFloat(ans.payment.amount) * 100
break
case 'empty':
answ = null
break
default:
answ = ans[ans.type]
break

return answ
)
return lam
)
return res.status(200).json(surveys)
})


In schema I have access to an array of all the question IDs from 1 form.



Thanks in advance!



EDIT 1
Example output of a survey with 10 questions.



 [
[["ZoW7FL2pVKvR","gfds"],
["amx5Q2JU4Qa7","Car 1"],
["jlqW0xFRGXdm","No"],
["FhfIURjvE8nN","dfs@hotmail.com"],
["vVTYmlvc1YIy",0]
["DqX2Dy0cvmMy","fezfze"]],

[["ZoW7FL2pVKvR", "Ruben"],
["ihNcWeYgZHPb","Male"],
["amx5Q2JU4Qa7","Car 2"],
["jlqW0xFRGXdm", "Yes"],
["FhfIURjvE8nN","ruben@gmail.com"],
["vVTYmlvc1YIy", 2],
["b8y0pDw3gYpn","No"],
["beeg0rtb7Mai","1995-02-10T00:00:00Z"],
["Knox8dyeM4Ak",10]]
]


This is the array of the all the questionIDs from 1 survey



"columnID": [
"ZoW7FL2pVKvR",
"ihNcWeYgZHPb",
"amx5Q2JU4Qa7",
"jlqW0xFRGXdm",
"FhfIURjvE8nN",
"vVTYmlvc1YIy",
"b8y0pDw3gYpn",
"beeg0rtb7Mai",
"Knox8dyeM4Ak",
"DqX2Dy0cvmMy"
]










share|improve this question
















I'm retrieving answers from the Typeform API. I'll put these answers into a dataset where the questions are the column names.
All of this works, untill a question isn't answered.
This doesn't return a null value.
For example:



Questions : [A, B, C, D]



Answers: [a, c, d] -> Question B didn't receive an answer.



I expect an output of [a, null, c, d] for above example.



I tried multiple ways to implement this in my code, but I don't find the right answer.



 let surveys = formsAnswer.items.map(survey => 
let i = 0
let lam = survey.answers.map(ans =>
let answ
let rightID2 = schema.map(findID =>
if (findID.id.toLowerCase() === req.body.id)
let id = findID.columnID[i]
i++
return id

)
switch (ans.type)
case 'boolean':
answ = ans.boolean ? 'Yes' : 'No'
break
case 'choice':
answ = ans.choice.label
break
case 'payment':
answ = parseFloat(ans.payment.amount) * 100
break
case 'empty':
answ = null
break
default:
answ = ans[ans.type]
break

return answ
)
return lam
)
return res.status(200).json(surveys)
})


In schema I have access to an array of all the question IDs from 1 form.



Thanks in advance!



EDIT 1
Example output of a survey with 10 questions.



 [
[["ZoW7FL2pVKvR","gfds"],
["amx5Q2JU4Qa7","Car 1"],
["jlqW0xFRGXdm","No"],
["FhfIURjvE8nN","dfs@hotmail.com"],
["vVTYmlvc1YIy",0]
["DqX2Dy0cvmMy","fezfze"]],

[["ZoW7FL2pVKvR", "Ruben"],
["ihNcWeYgZHPb","Male"],
["amx5Q2JU4Qa7","Car 2"],
["jlqW0xFRGXdm", "Yes"],
["FhfIURjvE8nN","ruben@gmail.com"],
["vVTYmlvc1YIy", 2],
["b8y0pDw3gYpn","No"],
["beeg0rtb7Mai","1995-02-10T00:00:00Z"],
["Knox8dyeM4Ak",10]]
]


This is the array of the all the questionIDs from 1 survey



"columnID": [
"ZoW7FL2pVKvR",
"ihNcWeYgZHPb",
"amx5Q2JU4Qa7",
"jlqW0xFRGXdm",
"FhfIURjvE8nN",
"vVTYmlvc1YIy",
"b8y0pDw3gYpn",
"beeg0rtb7Mai",
"Knox8dyeM4Ak",
"DqX2Dy0cvmMy"
]







javascript node.js typeform






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 17:43









Nicolas Grenié

3,5321 gold badge11 silver badges29 bronze badges




3,5321 gold badge11 silver badges29 bronze badges










asked Mar 25 at 15:50









D.DsnD.Dsn

586 bronze badges




586 bronze badges












  • I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

    – Wimanicesir
    Mar 25 at 15:58











  • The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

    – D.Dsn
    Mar 25 at 16:15











  • Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

    – Francis Leigh
    Mar 25 at 16:22











  • Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

    – Wimanicesir
    Mar 25 at 16:23











  • The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

    – Francis Leigh
    Mar 25 at 16:25

















  • I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

    – Wimanicesir
    Mar 25 at 15:58











  • The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

    – D.Dsn
    Mar 25 at 16:15











  • Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

    – Francis Leigh
    Mar 25 at 16:22











  • Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

    – Wimanicesir
    Mar 25 at 16:23











  • The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

    – Francis Leigh
    Mar 25 at 16:25
















I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

– Wimanicesir
Mar 25 at 15:58





I don't get the problem? Don't use null but just use 0? your array will be [a,0,c,d]

– Wimanicesir
Mar 25 at 15:58













The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

– D.Dsn
Mar 25 at 16:15





The problem isn't about 0 or null. It's if I have an array of questions [A, B, C, D], and the person only answered questions [A, C, D]. Then I retrieve the answer C on the index of question B. In my variable lam I map over these retrieved answers, but I need to find a way where I can check the id of the answered question, and match this with the index of the questions.

– D.Dsn
Mar 25 at 16:15













Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

– Francis Leigh
Mar 25 at 16:22





Before the user chooses an answer, initialise an Array of null items matching the length of how many questions there are. [null, null, null, null] Then upon interaction from the user you can take the questions answer and plop it into place of the initial array. if the user does not answer one atleast now you will have a null in-place of that question.

– Francis Leigh
Mar 25 at 16:22













Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

– Wimanicesir
Mar 25 at 16:23





Well, because you push NULL, the place will be empty, however if u push 0, it will take the place of B. So [A,B,C,D] and [A,0,C,D], C has same index. So yeah, the problem is about 0 or null

– Wimanicesir
Mar 25 at 16:23













The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

– Francis Leigh
Mar 25 at 16:25





The output seems flawed in order to validate specific questions. you could validate specific sections based on length of answers against length of array in output but in order to match answers up to questions you'd need some sort of key/id Link

– Francis Leigh
Mar 25 at 16:25










2 Answers
2






active

oldest

votes


















1














I can't tell you, why the answer is not in your list, because I don't understand your code, but I might be able to help you get the array, you want.



Assume you have an array with the ids of all questions called questionIds



const allAnswers = questionIds.map(questionId => getAnswerForQuestionByQuestionId(questionId, answers)

function getAnswerForQuestionByQuestionId(questionId, answers)
for(const answer of answers)
if (answer[0] === questionId)
return answer[1]


return null



This will return the array you are looking for.






share|improve this answer


















  • 1





    This solved it! Thanks!

    – D.Dsn
    Mar 25 at 22:28











  • You're welcome!

    – Woozar
    Mar 26 at 12:50


















1














You could map the whole anser array and build new arrays with prefilled null values and assign each given value to the wanted index.






var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 








share|improve this answer























  • This also worked, thanks! But bit more complex then the accepted answer.

    – D.Dsn
    Mar 25 at 22:28













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55341663%2fhow-can-i-enter-null-values-on-indexes-where-2-arrays-dont-match%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I can't tell you, why the answer is not in your list, because I don't understand your code, but I might be able to help you get the array, you want.



Assume you have an array with the ids of all questions called questionIds



const allAnswers = questionIds.map(questionId => getAnswerForQuestionByQuestionId(questionId, answers)

function getAnswerForQuestionByQuestionId(questionId, answers)
for(const answer of answers)
if (answer[0] === questionId)
return answer[1]


return null



This will return the array you are looking for.






share|improve this answer


















  • 1





    This solved it! Thanks!

    – D.Dsn
    Mar 25 at 22:28











  • You're welcome!

    – Woozar
    Mar 26 at 12:50















1














I can't tell you, why the answer is not in your list, because I don't understand your code, but I might be able to help you get the array, you want.



Assume you have an array with the ids of all questions called questionIds



const allAnswers = questionIds.map(questionId => getAnswerForQuestionByQuestionId(questionId, answers)

function getAnswerForQuestionByQuestionId(questionId, answers)
for(const answer of answers)
if (answer[0] === questionId)
return answer[1]


return null



This will return the array you are looking for.






share|improve this answer


















  • 1





    This solved it! Thanks!

    – D.Dsn
    Mar 25 at 22:28











  • You're welcome!

    – Woozar
    Mar 26 at 12:50













1












1








1







I can't tell you, why the answer is not in your list, because I don't understand your code, but I might be able to help you get the array, you want.



Assume you have an array with the ids of all questions called questionIds



const allAnswers = questionIds.map(questionId => getAnswerForQuestionByQuestionId(questionId, answers)

function getAnswerForQuestionByQuestionId(questionId, answers)
for(const answer of answers)
if (answer[0] === questionId)
return answer[1]


return null



This will return the array you are looking for.






share|improve this answer













I can't tell you, why the answer is not in your list, because I don't understand your code, but I might be able to help you get the array, you want.



Assume you have an array with the ids of all questions called questionIds



const allAnswers = questionIds.map(questionId => getAnswerForQuestionByQuestionId(questionId, answers)

function getAnswerForQuestionByQuestionId(questionId, answers)
for(const answer of answers)
if (answer[0] === questionId)
return answer[1]


return null



This will return the array you are looking for.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 17:10









WoozarWoozar

18713 bronze badges




18713 bronze badges







  • 1





    This solved it! Thanks!

    – D.Dsn
    Mar 25 at 22:28











  • You're welcome!

    – Woozar
    Mar 26 at 12:50












  • 1





    This solved it! Thanks!

    – D.Dsn
    Mar 25 at 22:28











  • You're welcome!

    – Woozar
    Mar 26 at 12:50







1




1





This solved it! Thanks!

– D.Dsn
Mar 25 at 22:28





This solved it! Thanks!

– D.Dsn
Mar 25 at 22:28













You're welcome!

– Woozar
Mar 26 at 12:50





You're welcome!

– Woozar
Mar 26 at 12:50











1














You could map the whole anser array and build new arrays with prefilled null values and assign each given value to the wanted index.






var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 








share|improve this answer























  • This also worked, thanks! But bit more complex then the accepted answer.

    – D.Dsn
    Mar 25 at 22:28















1














You could map the whole anser array and build new arrays with prefilled null values and assign each given value to the wanted index.






var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 








share|improve this answer























  • This also worked, thanks! But bit more complex then the accepted answer.

    – D.Dsn
    Mar 25 at 22:28













1












1








1







You could map the whole anser array and build new arrays with prefilled null values and assign each given value to the wanted index.






var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 








share|improve this answer













You could map the whole anser array and build new arrays with prefilled null values and assign each given value to the wanted index.






var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 








var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 





var answers = [[["ZoW7FL2pVKvR", "gfds"], ["amx5Q2JU4Qa7", "Car 1"], ["jlqW0xFRGXdm", "No"], ["FhfIURjvE8nN", "dfs@hotmail.com"], ["vVTYmlvc1YIy", 0], ["DqX2Dy0cvmMy", "fezfze"]], [["ZoW7FL2pVKvR", "Ruben"], ["ihNcWeYgZHPb", "Male"], ["amx5Q2JU4Qa7", "Car 2"], ["jlqW0xFRGXdm", "Yes"], ["FhfIURjvE8nN", "ruben@gmail.com"], ["vVTYmlvc1YIy", 2], ["b8y0pDw3gYpn", "No"], ["beeg0rtb7Mai", "1995-02-10T00:00:00Z"], ["Knox8dyeM4Ak", 10]]],
questions = ["ZoW7FL2pVKvR", "ihNcWeYgZHPb", "amx5Q2JU4Qa7", "jlqW0xFRGXdm", "FhfIURjvE8nN", "vVTYmlvc1YIy", "b8y0pDw3gYpn", "beeg0rtb7Mai", "Knox8dyeM4Ak", "DqX2Dy0cvmMy"],
indices = Object.assign(...questions.map((k, i) => ( [k]: i ))),
remapped = answers.map(a => a.reduce((r, b) =>
r[indices[b[0]]] = b;
return r;
, Array.from( length: questions.length ).fill(null)));

console.log(remapped);

.as-console-wrapper max-height: 100% !important; top: 0; 






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 17:34









Nina ScholzNina Scholz

213k16 gold badges127 silver badges193 bronze badges




213k16 gold badges127 silver badges193 bronze badges












  • This also worked, thanks! But bit more complex then the accepted answer.

    – D.Dsn
    Mar 25 at 22:28

















  • This also worked, thanks! But bit more complex then the accepted answer.

    – D.Dsn
    Mar 25 at 22:28
















This also worked, thanks! But bit more complex then the accepted answer.

– D.Dsn
Mar 25 at 22:28





This also worked, thanks! But bit more complex then the accepted answer.

– D.Dsn
Mar 25 at 22:28

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55341663%2fhow-can-i-enter-null-values-on-indexes-where-2-arrays-dont-match%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현