Arrays in type script

后端 未结 3 458
陌清茗
陌清茗 2021-02-05 00:52

I am finding difficulty declaring array in typescript and accessing it.

below is the code working for me

class Book {
    public BookId: number;
    publ         


        
3条回答
  •  太阳男子
    2021-02-05 01:17

    You can also do this as well (shorter cut) instead of having to do instance declaration. You do this in JSON instead.

    class Book {
        public BookId: number;
        public Title: string;
        public Author: string;
        public Price: number;
        public Description: string;
    }
    
    var bks: Book[] = [];
    
     bks.push({BookId: 1, Title:"foo", Author:"foo", Price: 5, Description: "foo"});   //This is all done in JSON.
    

提交回复
热议问题