There is no 'forEach' property that exists within the type 'Employee'

When trying to loop through a JSON object returned from a GET request, I encountered an error saying: Property 'forEach' does not exist on type 'Employee'. The Employee type is an observable.

This issue arises in Angular 7.

employee: Employee[];

single: any = [
    {
      "name": [],
      "value": []
    }      
  ];
chartData(id){
    return this.employeeService.getEmpSkill(id)
      .subscribe( data => data.forEach((i) => {this.single.push({name: (i.skill_name), value: (i.score) })
      this.single = [...this.single]
      console.log(this.single)

    }));      
  }

https://i.sstatic.net/WyYEA.png

My goal was to receive an array for chart data, but instead, I received the following error: error TS2339: Property 'forEach' does not exist on type 'Employee'.

Answer №1

Response provided by @toskv I noticed that your service is returning Observables instead of Observable. It would be beneficial for you to review your types and APIs to ensure that you are handling the responses accurately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Spring MVC 3 to serve a Spring-Data Page as JSON

I've built a data access layer using Spring-Data, and now I'm developing a web application on top of it. One controller method needs to return a Spring-Data Page formatted as JSON. This Page is essentially a List with additional information like ...

Dropdown with grouped options in Angular PrimeNG - displaying data other than the default label/value pair

Hello there, I've encountered some difficulties with the dropdown menu, specifically when it comes to organizing by groups. Initially, I faced challenges understanding the specific format required for the array used in options to populate the dropdow ...

Having difficulty implementing a versatile helper using Typescript in a React application

Setting up a generic for a Text Input helper has been quite challenging for me. I encountered an error when the Helper is used (specifically on the e passed to props.handleChange) <TextInput hiddenLabel={true} name={`${id}-number`} labelText=" ...

Ensure that the database is properly configured before running any test suites

Currently, I am facing the challenge of seeding my database with all the necessary resources required to successfully test my API. These tests are spread across multiple files. Is there a method that will allow me to fully seed the database before any tes ...

Retrieving and Modifying the Value of a Nested JSON Attribute

My JSON data is structured in a nested format, similar to the example below: { "eventId" : "12345", "eventName" : "carnival", "object": { "objectId" : "5678", "objectFiles" : [{"fileName":"text.txt", "fileContent":"This is a test file."}, ...

Exploring the functionality of window.matchmedia in React while incorporating Typescript

Recently, I have been working on implementing a dark mode toggle switch in React Typescript. In the past, I successfully built one using plain JavaScript along with useState and window.matchmedia('(prefers-color-scheme dark)').matches. However, w ...

Exploring the depths of useDispatch and dispatch in React-Redux

I am currently analyzing the code written by a former colleague of mine. Based on my understanding, useDispatch accepts an object containing the action type and payload, which is then compared to all reducers to update the state accordingly. However, in t ...

Tips for preventing empty JSON Array elements from being deserialized in a JSON String when utilizing Jackson

I am currently working with the Jackson 2 library and I'm facing a challenge while trying to deserialize a JSON response. The response structure is as follows: { "employee": [ {}, { "Details": [ { "Name ...

Is there a way to utilize multiple HTML templates with the same TypeScript file?

Is it possible to use different HTML templates for the same TypeScript file, based on an expression in the constructor? I am looking for something like this: <div class="container-fluid"> <app-teste1 *ngIf="teste == '1'> & ...

Contrasts between { [P in keyof any]: number } and { [P in string | number | symbol]: number }

As a newcomer to TypeScript, I've noticed a discrepancy between keyof any and string | number | symbol in MappedType. However, I'm unclear on the exact distinction between these two syntaxes. type T = keyof any; //string | number | symbol type T ...

Discover the initial item in Observable that meets a certain criteria

I am trying to retrieve the first item of type avatar from payload.result within an observable: let result = this.fileService.getAvatarByUserId(2).pipe( map((payload: Payload<FileModel[]>) => payload.result), first((result: FileModel[]) => ...

What is the importance of having Actions and Reducers in Redux?

I am trying to grasp the reasoning behind the design of Redux. For instance, let's consider a scenario where I have a store with a list of todos. If the store is represented as an object like this: {1: todo1, 2: todo2, 3: todo3, ...}* And we enca ...

Using PostgreSQL to tally occurrences and store them as JSON key/value pairs

In PostgreSQL 9.4, I have a task where I need to analyze an array of text elements to calculate the frequency of each element and return the results in a JSON object format, where the key is the text element and the value is the count. Scenario 1 - No ref ...

Having Trouble Saving Nested JSON Array in MongoDB with Mongoose

Within Postman, I currently have JSON data structured like this: { "hostname": [ { "item": [ { "system": "10l313", "severity": "2" }, { ...

A step-by-step guide on recovering information from a JSON file within Angular 12

Being a novice developer, I have taken on the challenge of creating a quiz application using Angular 12 to enhance my coding skills. However, I've hit a roadblock when it comes to retrieving data with questions and answers from a JSON file. Despite su ...

Reorganizing Firebase data in Ionic 2

I am currently working on an exciting project to develop an Ionic notes application, where users can easily rearrange items in the list using the reorderArray() function. However, I encountered an issue with Firebase resulting in an error message related t ...

The superlative system for encoding emojis

In my current setup, I have the following environment: Client -> iOS App, Server -> PHP and MySQL. Data from the client to the server is transferred via HTTP POST. Data from the server to the client is transmitted using JSON. I am interested in ad ...

Exploring Typescript: Uncovering the Secrets of the navigator.connection Property

I am trying to access the NetworkInformation interface by using a simple TypeScript function like the one shown below: private checkNetworkConnection(): void { const connection = Navigator.connection || navigator.mozConnection || navigator.webkitConn ...

Initial value not displayed in Angular Reactive Forms Select component

I'm having trouble loading predefined values into selects within an Angular reactive form. The initial value isn't displaying properly. These predefined values are in object form, and I'm not sure if this is causing the issue. For a sample ...

Storing Scrapy results in separate JSON entities using a while loop

Using a while-loop to scrape various fields on a webpage, I aim to store the output for each loop iteration in separate json objects. While this process functions flawlessly on my local machine with Scrapy 0.24.6 and Python 2.7.5, it encounters issues on ...