How can i select al the values in a row of an array?


I want to choose all the values in the column st_teff, so i can do some calculations to create a chart.
I’ve used

temperature = Object.values(newDataPlanetas).map(d => d.st_teff)

to get all the values in the array to create a flat array but when i use the function:

function getArray(newDataPlanetas) {

const transformedArray = ;

for (const row of newDataPlanetas) {
const transformedRow = {};
for (const column of columnsToKeep) {
transformedRow[column] = row[column];
}

  if(temperature < 3500){
    transformedArray.push(Object.assign({}, transformedRow, {bolcon: -2.0}));
}

}
return transformedArray;
}

to fill the array object bolcon if it has the right temperature, but after adding the if it doesn’t fill the array, if i remove the array it fills the array but add bolcon -2 to all values.
This function creates a new array with the columns:

columnsToKeep = Array(4) [“st_teff”, “sy_vmag”, “sy_dist”, “spectClass”]

With this function i fill the array with the data st_teff, sy_vmag, sy_distance. Bolcon column is added after the if, spect class is aded but later on

Do you mean this?

if (row.temperature < 3500) {

Otherwise, temperature would refer to the cell (an array of temperatures), not the temperature field of the current row.

By the way, you may be able to simplify your code like so:

transformedData = newDataPlanetas
  .filter(d => d.temperature < 3500)
  .map(d => ({...d, bolcon: -2}))

I want to choose all the elements in the st_teff column. (As shown in the rectangle)

I created >temperature = Object.values(newDataPlanetas).map(d => d.st_teff)
this flat array to use instead of >newDataPlanetas.st_teff
(which doesn’t give me the entire column)

I want to iterate that column so i can compare temperatures and assign the right bolcon and spect class according to the temperature.

Could you share the link to the notebook here? You will have to publish it (could publish it as unlisted just to share the link here).

Here’s the link.
I need to iterate through the st_teff (star temp) column, so i can assign the correct spec and bolcon, to calculate the absolute magnitude and then calculate the luminosity.

I sent you a suggestion (added some example code at the bottom of your notebook):
https://observablehq.com/compare/70a147b2e06f4bf0...649734321f29c0b7

1 Like