map() get() confusion

前端 未结 3 924
终归单人心
终归单人心 2020-12-01 08:18

I\'m just going through the jQuery API and I\'m a bit confused on map() & get() method. I know I\'m wrong but the map() method lo

3条回答
  •  悲哀的现实
    2020-12-01 08:27

    map loops through a jQuery object and applies a function to each element. The return value of each call is added into an array. That array is then wrapped into a jQuery object and returned.

    get returns an array containing each element in a jQuery object. This means that it essentially unwraps the selection returned by map and gets a plain JS array.

    In your example, map creates a selection containing the height of each element. You then call get on it so that the native JS function Math.max can understand it. this.height() then sets the height of each element in the selection to the largest value in the array.

提交回复
热议问题