Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
a way of getting types from map function

New react developer, i am getting an array of objects(identifier:'' and name:'') in console, i want to know is there a way to know what kind of type am i getting (for example are 'name's boolean, string, number...?)

console.log("data",stateToProps?.map((data) => data.name) );

Sometimes at work i get to refactor others code and to add typescript, this would help me alot. any suggestions ?

const stateToProps = useSelector((state) => {
  const articles = {
    sites: state.articles.sites,
    brokers: state.siteArticles.brokers,
  };

  return articles[props.action];
});

console.log("data", stateToProps);

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

For JS types, you can write it like this :

const stateToProps = useSelector((state) => {
  const articles = {
    sites: state.articles.sites,
    brokers: state.siteArticles.brokers,
  };

  return articles[props.action];
});

function getTypeName(val) {
    return {}.toString.call(val).slice(8, -1);
  }
console.log(
    "data",
    mapStateToProps?.map((data) => getTypeName(data.name))
  );

about 4 years ago · Juan Pablo Isaza Report

0

You will have to use typeof for each one of the elements

const stateToProps = [{name: "X", value: 2}, {name: undefined, value: 2}, {name: [], value: 2}, {name: true, value: 2}]

console.log("data", stateToProps.map((element) => typeof element.name));

about 4 years ago · Juan Pablo Isaza Report

0

You can use javascript's typeof operator: https://www.w3schools.com/js/js_typeof.asp

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!