It looks like those are what we call parallel arrays: The element at index n of one array relates to the element at index n of the other.
That being the case, you can use a simple for loop and brackets property notation:
const result = {};
for (let index = 0; index < array1.length; ++index) {
result[array1[index]] = array2[index];
}
Live Example:
const array1 = [
"PT",
"ES",
"FR",
"CH",
"BR",
"DE",
];
const array2 = [
100,
400,
550,
200,
400,
500,
];
const result = {};
for (let index = 0; index < array1.length; ++index) {
result[array1[index]] = array2[index];
}
console.log(result);
You can also use map with Object.fromEntries to create the object, but it's more complicated (though shorter) and involves temporary array objects:
const result = Object.fromEntries(
array1.map((array1value, index) => [array1value, array2[index]])
);
Live Example:
const array1 = [
"PT",
"ES",
"FR",
"CH",
"BR",
"DE",
];
const array2 = [
100,
400,
550,
200,
400,
500,
];
const result = Object.fromEntries(
array1.map((array1value, index) => [array1value, array2[index]])
);
console.log(result);
Side note: In your output, you've shown the values 100, 200, etc. as strings, but they're numbers in your input. If you want them to be strings, just convert them as you go, like this:
const result = {};
for (let index = 0; index < array1.length; ++index) {
result[array1[index]] = String(array2[index]);
// −−−−−−−−−−−−−−−−−−−−−−−−−^^^^^^^−−−−−−−−−−−−−^
}
Live Example:
const array1 = [
"PT",
"ES",
"FR",
"CH",
"BR",
"DE",
];
const array2 = [
100,
400,
550,
200,
400,
500,
];
const result = {};
for (let index = 0; index < array1.length; ++index) {
result[array1[index]] = String(array2[index]);
}
console.log(result);
You'll get people pointing you at reduce, but reduce is only useful when you're doing functional programming with predefined, reusable reducer functions. Otherwise, it's just an overcomplicated, error-prone loop where using an actual loop would be clearer and easier to get right.
In a comment you've asked:
What If I want it do be like this? [{ text: 'pt', value: 100, }, { text: 'es', value: 500, }] ?
To do that, you want to create an object for each entry in the array. You can create the array via map, and you can create an object using an object literal ({text: "PT", value: 100} and similar, but getting the values from the array):
const result = array1.map((text, index) => ({text: text, value: array2[index]}));
or using shorthand property notation for the text property:
const result = array1.map((text, index) => ({text, value: array2[index]}));
Live Example:
const array1 = [
"PT",
"ES",
"FR",
"CH",
"BR",
"DE",
];
const array2 = [
100,
400,
550,
200,
400,
500,
];
const result = array1.map((text, index) => ({text, value: array2[index]}));
console.log(result);
I've left those text values in upper case, but if you want to make them lower case in the objects, use .toLocaleLowerCase() on them:
const result = array1.map((text: text.toLocaleLowerCase(), index) => ({text, value: array2[index]}));