如何将对象插入对象x次?

时间:2018-01-30 02:51:44

标签: javascript loops object

我有这个对象:

IEqualityComparer < HashSet<int> > hashSetComparer = HashSet<int>.CreateSetComparer();
        var h3 = new HashSet<HashSet<int>>( hashSetComparer ) { new HashSet<int>{ 1, 2 }, new HashSet<int>{ 3, 4 } };
        var h4 = new HashSet<HashSet<int>>( hashSetComparer ) { new HashSet<int>{ 4, 3 }, new HashSet<int>{ 1, 2  } };

        var h6 = new HashSet<HashSet<int>>() { new HashSet<int>{ 4, 3 }, new HashSet<int>{ 1, 2  } };

        bool b13 = h4.Contains( new HashSet<int>{ 1, 2 } ); //true
        bool b15 = h6.Contains( new HashSet<int>{ 1, 2 } ); //false

        bool b10 = h3.SetEquals( h4 ); //true

        IEqualityComparer < HashSet < HashSet<int> >>  comparer2 = HashSet<HashSet<int>>.CreateSetComparer();
        bool b14 = comparer2.Equals( h3, h4 ); //true

        //var h5 = new HashSet<HashSet<HashSet<int>>>( HashSet<HashSet<int>>.CreateSetComparer() );
        var h5 = new HashSet<HashSet<HashSet<int>>>( comparer2 );
        h5.Add( h3 );
        bool b11 = h5.Contains( h3 ); //true
        bool b12 = h5.Contains( h4 );//FALSE! WHY?

我想在const items = { 0: { property: 'test', }, }; 内创建8个对象,所以我尝试了这个:

item

但这只记录const items = { 0: { property: 'test', }, }; for (var i = 0; i < 9; i++) { console.log(items[i]); } 8次。关于如何记录这样的事情的任何想法?

undefined

1 个答案:

答案 0 :(得分:2)

这是怎么做的:

for (var i = 0; i < 9; i++) {
  items[i] = {'property': 'test'}
}

然后看看:

console.log(items)